Announcement

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

    Filtering in ListGrid with datasource from database

    I do have ListGrid with datasource.xml file created by builder.
    Pretty much straight forward.

    Also I've added this:
    ....
    for (int i = 0; i < dsf.length - 1; i++) {
    DataSourceField ff = dsf[i];

    if (ff.getAttribute("foreignKey") != null) {
    ff.setEditorType(new ComboBoxItem());
    }
    }

    .....

    listGrid.setShowFilterEditor(true);

    to set editor for current column and have ability to choose appropriate value from table linked by foreign key, and it works!
    What doesn't work - that same list of values from lookup table aren't get populated in Filter columns which are displayed like Comboboxes as well.

    How to solve the problem?

    #2
    Are you already setting filterEditorType with a ComboBoxItem with the same optionDataSource setting? That's required.

    Comment


      #3
      Does it mean that I have to set custom setOptionDataSource() for each Combobox filterable columns?

      Comment


        #4
        Not "custom" for each column, just match what you're using with setEditorType().

        Comment


          #5
          Still not celar,
          I can do something like that:

          Code:
          		listGrid.setAutoFetchData(false);
          		listGrid.fetchData();
          
          		DataSourceField[] dsf = ds.getFields();
          		ListGridField[] lsf = listGrid.getFields();
          		for (int i = 0; i < dsf.length - 1; i++) {
          			DataSourceField ff = dsf[i];
          			ListGridField lf = lsf[i]; // Exception here
          			if (ff.getAttribute("foreignKey") != null) {
          				ComboBoxItem cb = new ComboBoxItem();
          				ff.setEditorType(cb);
          				lf.setFilterEditorType(cb);
          			}
          		}
          But that gives me exception....

          Comment


            #6
            Apparently to perform ListGridField .setFilterEditorType(cb); in my case wont be possible, because at the moment I want to set something for the filter, ListGrid fields do not exist yet.

            Comment


              #7
              Here is the piece of my code that creates listgrid and assigns datasource to it. Datasource defined in XML and it is works with Database via smartGWTEE Pro server side.

              What would be the place to put the code for assigning proper FilterDataSource / filterEditor ?

              Code:
              		final DataSource ds = DataSource.get(dbName);
              		
              		DataSourceField[] dsf = ds.getFields();
              		
              		for (int i = 0; i < dsf.length - 1; i++) {
              			DataSourceField ff = dsf[i];
              			if (ff.getAttribute("foreignKey") != null) {
              				ComboBoxItem cb = new ComboBoxItem();
              				cb.setHeight(30); // just to see that is not generic ComboBox
              				ff.setEditorType(cb);
              			}
              		}
              
              		final ListGrid listGrid = new ListGrid();
              
              		listGrid.setDataSource(ds);
              		listGrid.setUseAllDataSourceFields(true);
              
              		listGrid.setHeight100();
              		listGrid.setWidth100();
              		listGrid.setShowFilterEditor(true);
              		listGrid.setShowRecordComponents(true);        
              		listGrid.setAlternateRecordStyles(true);
              		listGrid.setShowAllRecords(true);
              		listGrid.setCanEdit(true);
              		listGrid.setAutoFetchData(false);
              		listGrid.fetchData();

              Comment

              Working...
              X