无法刷新GXT ListField

时间:2013-08-08 17:34:19

标签: java gxt

概览

我使用动态GXT ListField列出DB中某个位置的所有批准者,并预先选择所选批处理者(isSelected == true)。

问题:

看起来商店拥有正确的数据并在列表中选择正确的序号,但可见ListField中的数据仍然是在第一次加载ListField时显示数据。我无法刷新列表UI以显示第二个位置的项目。

示例:

LOCATION1:

  

所有批准人= {a,b,c,d,e,f,g,h,i,j}

     

选定的审批人= {a,b,c}

     

display = { [a],[b],[c] ,d,e,f,g,h,i,j}其中 [] =选择

LOCATION2:

  

所有批准者= {x,y,z,l,m,n,o,p,q,r}

     

选择的审批人= {x,y,z,l}

     

display = { [a],[b],[c],[d] ,e,f,g,h,i,j}其中[] =已选择(错误!)

     

预期= { [x],[y],[z],[l] ,m,n,o,p,q,r}

     

注意:它现在已选择 4 ,这意味着它使用正确   store,display仍显示location1数据:(

CODE:

ListField<Approver>() approversListField ;

    OnModuleload() //..not including for simplicity
    {
    :

    panel.add(getInitialApproverList());
    loadApprovers(1);
    loadApprovers(2);
    }

        private Widget getInitialApproverList() {

            approversListField = new ListField<Approver>();
            approversListField.setEmptyText("employee last name");
            approversListField.setTemplate(getApproverTemplate());
            approversListField.setFieldLabel("Approvers *");
            approversListField.setId("approvers");
            approversListField.setEmptyText("No approvers available.");

                return approversListField;

        }

        private void loadApprovers(int locationID) {

                ListStore<Approver> approversStore = dataStores.getApprovers(locationID);           
                approversListField.setStore(approversStore);
                approversListField.setValueField("userID");
                approversStore.addStoreListener(new StoreListener<Approver>() {
                    @Override
                    public void storeDataChanged(StoreEvent<Approver> se) {
                        super.storeDataChanged(se);

                        approversListField.fireEvent(Events.Render);

                    }
                });

                /**
                 * // * Attach render listener, had to do it on render because select()
                 * // * method only works onrender // *
                 * http://www.sencha.com/forum/showthread.php?55659-Selecting-Items-in-ListField-After-Load // *
                 */
                approversListField.addListener(Events.Render, new Listener<BaseEvent>() {
                    @Override
                    public void handleEvent(BaseEvent be) {

                        ListViewSelectionModel<Approver> approverListFieldSelectionModel = approversListField.getListView()
                                .getSelectionModel();


                        approversListField.getListView().refresh();
                        approverListFieldSelectionModel.deselectAll();                                      

                        System.out.println("approversStore size:"+approversListField.getStore().getCount());
                        for (int i = 0; i < approversListField.getStore().getCount(); i++) {
                            Approver app = approversListField.getStore().getAt(i);

                            System.out.println(app);                    
                            if (app.isSelected() == true) {

                                System.out.println("FOUND THE APPROVER!  " + i);
                                approverListFieldSelectionModel.select(app, true);                                                                              

                            }
                        }

                    }
                });

        }

1 个答案:

答案 0 :(得分:0)

终于找到了自己。离开这里是为了它的价值。

如果商店发生变化,您也必须为Listfield的商店重置商店。

approversListField.getListView().setStore(approversListField.getStore());

无需触发Render.Can可以更改商店数据。

approversStore.addStoreListener(new StoreListener<Approver>() {
            @Override
            public void storeDataChanged(StoreEvent<Approver> se) {
                super.storeDataChanged(se);

                ListViewSelectionModel<Approver> approverListFieldSelectionModel = approversListField.getListView()
                        .getSelectionModel();
                approverListFieldSelectionModel.deselectAll();
                approversListField.getListView().setStore(approversListField.getStore());
                approversListField.getListView().refresh();
                for (int i = 0; i < approversListField.getStore().getCount(); i++) {                    
                    Approver app = approversListField.getStore().getAt(i);
                    if (app.getIsselected() == true) {                  
                        approverListFieldSelectionModel.select(i, true);

                    }
                }

            }
        });