Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    selectItem.getClientPickListData();does not always return all rows

    Hello again :) I have encountered another thing in the SelectItem class. Again, looking at your (https://www.smartclient.com/smartgwt...bobox_category) example, where you have a custom control with a "select all" button.

    You use the getClientPickListData to select all rows. However, I have noticed that for larger amounts of rows in the SelectItem, that method will only return a subset of the rows, and i'm not sure it's determinable which of the rows that are selected...

    I altered my testcase i gave you in the other thread to illustrate. I have a test datasource that returns 200 rows. If i click "select all" not all rows become selected, because the method does not return all rows.

    Check my GWT.log output(in the checkall button clickhandler). in my case it looked like this:
    >>> record size: 121, recordlist: 200
    So the
    getPickListData()
    returns 121 rows, while
    selectItem.getPickList().getDataAsRecordList()
    returns the correct 200 rows.

    But it's different, another time it was 125, another 149... so something is strange. (using 13d pro as usual)


    code:
    Code:
    public void onModuleLoad() {
    
            Canvas.resizeControls(20);
            DataSource ds = new BananaDS();
            final DynamicForm form = new DynamicForm();
            form.setWidth(500);
    
            SelectItem multipleSelect = new SelectItem("multipleSelect");
            multipleSelect.setWidth(200);
            multipleSelect.setPickListWidth(200);
            multipleSelect.setTitle("Select items");
    
            multipleSelect.setDisplayField("name");
            multipleSelect.setValueField("id");
            multipleSelect.setMultiple(true);
    
            multipleSelect.setMultiple(true);
            multipleSelect.setOptionDataSource(ds);
    
            ToolStrip toolStrip = new ToolStrip();
            toolStrip.setHeight(30);
            toolStrip.setWidth100();
    
            ToolStripButton checkAllButton = new ToolStripButton();
            checkAllButton.setWidth("50%");
            checkAllButton.setTitle("Check");
            checkAllButton.addClickHandler(event -> {
                SelectItem selectItem = (SelectItem) form.getField("multipleSelect");
                ListGridRecord records[] = selectItem.getClientPickListData();
                RecordList dataAsRecordList = selectItem.getPickList().getDataAsRecordList();
                String[] values = new String[records.length];
                for (int i = 0; i < records.length; i++) {
                    values[i] = records[i].getAttributeAsString("id");
                }
                selectItem.setValues(values);
                GWT.log(">>> record size: " + records.length + ", recordlist: " + dataAsRecordList.getLength());
                //PickListMenu pickList = (PickListMenu) selectItem.getCanvasAutoChild("pickList");
                //pickList.hide();
            });
            ToolStripButton checkNoneButton = new ToolStripButton();
            checkNoneButton.setWidth("50%");
            checkNoneButton.setTitle("Uncheck");
            checkNoneButton.addClickHandler(event -> {
                SelectItem selectItem = (SelectItem) form.getField("multipleSelect");
                selectItem.setValues(new String[0]);
                PickListMenu pickList = (PickListMenu) selectItem.getCanvasAutoChild("pickList");
                pickList.hide();
            });
            toolStrip.addMember(checkAllButton);
            toolStrip.addMember(checkNoneButton);
    
            ListGrid pickListProperties = new ListGrid();
            pickListProperties.setGridComponents(toolStrip, ListGridComponent.HEADER, ListGridComponent.BODY);
            multipleSelect.setPickListProperties(pickListProperties);
    
            form.setFields(multipleSelect);
            form.draw();
        }
    
    public class BananaDS extends DataSource {
    
            public BananaDS() {
    
                setID("Banana");
    
                DataSourceIntegerField pkField = new DataSourceIntegerField("id");
                pkField.setHidden(true);
                pkField.setPrimaryKey(true);
    
                DataSourceTextField nameField = new DataSourceTextField("name", "Name", 128, true);
                DataSourceTextField descriptionField = new DataSourceTextField("desc", "Description", 2000);
                setFields(pkField, nameField, descriptionField);
                setCacheData(getRecords());
                setClientOnly(true);
            }
    
            private Record[] getRecords(){
                int amount = 200;
                Record[] recs = new Record[amount];
                for (int i = 0; i < amount; i++) {
                    Record record = new Record();
                    record.setAttribute("id", i);
                    record.setAttribute("name", "name " + i);
                    record.setAttribute("desc", "desc " + i);
                    recs[i] = record;
                }
                return recs;
            }
        }

    #2
    In order to offer a "Select All" button, you need to ensure all rows are loaded. The sample does this by using criteria to limit the sample data. You can do it by setting useClientFiltering (among other ways).

    Comment


      #3
      Have to say this is pretty convoluted to me. You say that all items must be loaded but when i call the "selectItem.getPickList().getDataAsRecordList()" it does return all 200 rows so doesn't it mean that all rows indeed are loaded? Are these two methods different usecases? Hard to say from the javadocs.

      I did try selectItem.setUseClientFiltering() to both true and false, i did not see any difference. getClientPickListData() still does not return the full amount of rows.

      Yesterday, i tried lots of stuff to get the picklist to load all rows right away, mostly by trying to set properties on the PickList:
      Code:
      ListGrid props = new ListGrid();
      props.setDataFetchMode(FetchMode.LOCAL);
      props.setShowAllRecords(true);
      props.setDataPageSize(1000);
      
      dropdown.setPickListProperties(props);
      (since there is no datapagesize or datafetchmode on the selectitem itself)
      I couldn't get any of this to work either.
      Last edited by mathias; 18 Nov 2021, 23:04.

      Comment


        #4
        Both methods should work if all data is loaded.

        If you think that somehow all data is loaded but APIs are not returning it all, you should check the Developer Console's RPC tab to see whether that's true. That's the same thing to check to verify that your settings are working.

        Note that of course these settings just change what requests the client sends; if your server DataSource ignores those settings, or is somehow flawed (off by one on rows or whatever), then the client may end up with partial data even having requested full data.

        Comment


          #5
          Hey thanks for quick response.

          This is why i made the test case. If you run it you will see that the methods DO return different values from the selectitem, which is why i'm asking.
          I can't see why there would ever be possible for those two to return a different set of values, do you?

          Comment


            #6
            Some follow-up. I changed my test case to do 'real' idacalls. I cannot get the selectitem to do anything but fetch the first 75 rows (start- and end row parameters in the dsrequest).

            in the code below i have tried every combination of those parameters. Am i doing it wrong?

            Code:
            dropdown = new SelectItem(displayFieldToUse, title);
                    dropdown.setUseClientFiltering(false);//also true
                    ListGrid props = new ListGrid();
                    props.setShowAllRecords(true);//every combination of these 3 parameters
                    props.setDataPageSize(1000);
                    props.setDataFetchMode(FetchMode.LOCAL);
            
                    dropdown.setPickListProperties(props);

            Comment


              #7
              Hi again.
              Setting either dataPageSize or dataFetchMode as you have in this sample code should work for you.
              Here's a reworked version of your original sample, using the shipped "supplyItem" dataSource, that demonstrates this working with dataFetchMode:
              Code:
              public void onModuleLoad() {
              
                DataSource ds = DataSource.get("supplyItem"); //new BananaDS();
                final DynamicForm form = new DynamicForm();
              
                SelectItem multipleSelect = new SelectItem("multipleSelect");
                multipleSelect.setWidth(200);
                multipleSelect.setPickListWidth(200);
              
                multipleSelect.setTitle("Select items");
              
                multipleSelect.setDisplayField("itemName");
                multipleSelect.setValueField("SKU");
              
                multipleSelect.setMultiple(true);
              
                multipleSelect.setOptionDataSource(ds);
              
                ToolStrip toolStrip = new ToolStrip();
                toolStrip.setHeight(30);
                toolStrip.setWidth100();
              
                ToolStripButton checkAllButton = new ToolStripButton();
                checkAllButton.setWidth("50%");
                checkAllButton.setTitle("Show Total");
                checkAllButton.addClickHandler(new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                    SelectItem item = (SelectItem) form.getItem("multipleSelect");
                    SC.say("Total rows::" + item.getClientPickListData().length);
                  }
              
                });
              
                toolStrip.addMember(checkAllButton);
              
                ListGrid pickListProperties = new ListGrid();
                pickListProperties.setGridComponents(toolStrip, ListGridComponent.HEADER, ListGridComponent.BODY);
                pickListProperties.setDataFetchMode(FetchMode.LOCAL);
                multipleSelect.setPickListProperties(pickListProperties);
              
                form.setFields(multipleSelect);
                form.draw();
              }
              Something else must be going on in your usage, (possibly something to do with when items are instantiated in JavaScript in your app? Perhaps you're setting properties on a 'properties' type config object after its live component has already been created in JS or something?)

              If you can show us a runnable test case that demonstrates the problem we'll take a look

              Thanks
              Isomorphic Software

              Comment


                #8
                Hey there, thanks for responding. This dropdown should always show all records, so i solved it by ignoring the start- and endrows on the server... Will look into your feedback when i can get a minute to see if i can find anything related to your suggestions.

                Comment

                Working...
                X