Announcement

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

    ListGrid filtering with disconnected data

    Hello,

    I'm trying to build a ListGrid with disconnected (offline) data. I have set showFilterEditor to true. But when I apply some filter text, nothing happens.

    Is filtering only possible with data presentation controls connected to a DataSource? How can I use filtering with a disconnected data presentation control?

    Here is a test case:

    Code:
    public class DataTest2 implements EntryPoint
    {
    
      @Override
      public void onModuleLoad()
      {
    
        final ListGrid countryGrid = new ListGrid();
        countryGrid.setWidth( 350 );
        countryGrid.setHeight( 224 );
        countryGrid.setAlternateRecordStyles( true );
        countryGrid.setShowAllRecords( true );
    
        ListGridField countryCodeField = new ListGridField( "countryCode", "Code", 40 );
        ListGridField nameField = new ListGridField( "countryName", "Country", 120 );
        ListGridField capitalField = new ListGridField( "capital", "Capital" );
    
        countryGrid.setFields( countryCodeField, nameField, capitalField );
        countryGrid.setCanResizeFields( true );
        countryGrid.setData( createListGridRecords( countryRecords ) );
    
        countryGrid.setShowFilterEditor( true );
        countryGrid.draw();
      }
    
      private static final String[] countryRecords =
                                                       new String[]{ "countryCode;countryName;capital",
          "US;United States;Washington, DC", "CH;China;Beijing", "JA;Japan;Tokyo", "IN;India;New Delhi",
          "GM;Germany;Berlin", "UK;United Kingdom;London", "FR;France;Paris", "IT;Italy;Rome",
          "RS;Russia;Moscow", "BR;Brazil;Brasilia", "CA;Canada;Ottawa", "MX;Mexico;Mexico (Distrito Federal)",
          "SP;Spain;Madrid", "KS;South Korea;Seoul", "ID;Indonesia;Jakarta" };
      /**
       * Creates an array of <code>ListGridRecord</code> objects from an array of <code>String</code> values. The
       * first string in the array contains the names of the fields in the <code>ListGridRecord</code>s; the
       * remaining strings in the supplied array contain the data. The field names and data values are separated
       * by semicolons.
       * 
       * @param records An array of strings containing the field names (in the first string of the array) and the
       *          data values to be used in creating the resulting list grid records.
       * @return An array of list grid records representing the data.
       */
      public ListGridRecord[] createListGridRecords( String[] records )
      {
        ListGridRecord[] result = new ListGridRecord[records.length - 1];
        String[] fieldNames = records[ 0 ].split( ";" );
        for ( int recordIndex = 1; recordIndex < records.length; ++recordIndex )
        {
          String[] fieldValues = records[ recordIndex ].split( ";" );
          result[ recordIndex - 1 ] = new ListGridRecord();
          for ( int fieldIndex = 0; fieldIndex < fieldValues.length; ++fieldIndex )
          {
            result[ recordIndex - 1 ].setAttribute( fieldNames[ fieldIndex ], fieldValues[ fieldIndex ] );
          }
        }
        return result;
      } // createListGridRecords()
    
    }

    #2
    Use a clientOnly:true DataSource.

    Comment


      #3
      Hello Isomorphic,

      for some reason, I couldn't get it to work until now. Another fundamental question: Is filtering even possible without a DataSource? Can I do something like this:

      Code:
      ListGridRecord a = new ListGridRecord();
      a.setAttribute("id", 1);
      a.setAttribute("employeeName", "George");
      employeeListGrid.addData(a);
      
      ListGridRecord b = new ListGridRecord();
      b.setAttribute("id", 2);
      b.setAttribute("employeeName", "Jane");
      employeeListGrid.addData(b);
      and still use filtering?

      Comment


        #4
        Filtering requires information about field types, which a DataSource provides. Again, use a clientOnly DataSource.

        Comment


          #5
          I am also using the similar code and facing the same problem.
          How to add the dataSource in this code now , can anyone explain ?

          I tried the following code but this did not work


          DataSource dataSource = new DataSource();
          dataSource.setClientOnly(true);

          ListGridRecord a = new ListGridRecord();
          a.setAttribute("id", 1);
          a.setAttribute("employeeName", "George");
          dataSource.addData(a);

          ListGridRecord b = new ListGridRecord();
          b.setAttribute("id", 2);
          b.setAttribute("employeeName", "Jane");
          dataSource.addData(a);

          employeeListGrid.setDataSource(dataSource);
          Last edited by vgattani; 30 Nov 2009, 01:47.

          Comment


            #6
            Originally posted by vgattani
            DataSource dataSource = new DataSource();
            dataSource.setClientOnly(true);

            ListGridRecord a = new ListGridRecord();
            a.setAttribute("id", 1);
            a.setAttribute("employeeName", "George");
            dataSource.addData(a);

            ListGridRecord b = new ListGridRecord();
            b.setAttribute("id", 2);
            b.setAttribute("employeeName", "Jane");
            dataSource.addData(a);

            employeeListGrid.setDataSource(dataSource);
            employeeListGrid.fetchData();
            try to call employeeListGrid.fetchData() after setting the datasource. That worked for me. I think you can also set autoFetchData on the grid instead though I didn't test it.

            Comment

            Working...
            X