Announcement

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

    Local datasource

    Hello there,

    maybe a dumb question which was posted before. I would like to create local (custom filled) datasource. I know that power of datasources is in additionaly server-side funcionality but this is not what im actually looking for. The reason i don't want to use simple setData method of ListGrid (or other component) is that with this approach my live filter does not work (works only with datasource). I tried many was how to properly set datasource but sometimes I don't have data duplicated, sometimes i don't have any data show. Can you please provide some simple example how to do so? Thank you

    I'm adding my actual version which of course is wrong and I'm sure it has few constructs which it does not need (or do the same thing or won't do anything). I just tried to achieve what i really want various ways.

    Code:
    public abstract class LocalDatasource extends DataSource {
    
        private ListGrid grid;
    
        public LocalDatasource(ListGrid grid) {
            this.grid = grid;
            setTestData(new DataClass[]{});
            setClientOnly(true);
        }
    
        public void reloadRecords(Collection<ListGridRecord> records) {
            setTestData(new DataClass[]{});
            for (Record record : getCacheData()) {
                removeData(record);
                grid.removeData(record);
            }
            grid.invalidateCache();
            invalidateCache();
            for (TableRecord record : records) {
                addData(record); // add all
            }
            grid.fetchData();
        }
    
    }
    Last edited by d1x; 7 Mar 2012, 04:03.

    #2
    First of all, make your DataSource 'listgrid-aware' should be considered an error.

    Why don't your try something like:
    final DataSource ds = new DataSource(){{
    setClientOnly(true);
    setTestData(something);
    }};
    ListGrid grid = new ListGrid(){{
    setDataSource(ds);
    setAutoFetchData(true);
    }};
    ds.setTestData(newData);

    Comment


      #3
      Well being listgrid-aware is error because i should rather work with DataboundComponent or because it is some form of tight coupling which is not good in this case for SmartGWT?

      Anyway I updated my code a bit and made it working as I wanted.

      Code:
      public abstract class LocalDatasource extends DataSource {
      
          private DataBoundComponent dataComp;
      
          public LocalDatasource(DataBoundComponent dbc) {
              this.dataComp = dbc;
              setTestData(new DataClass[]{});
              setClientOnly(true);
          }
      
          public void reloadRecords(DataClass[] data) {
              setTestData(data);
              dataComp.fetchData(); // without these two lines,
              dataComp.filterData(); // live filter didnt work properly
          }
      }
      ... within ListGrid impl
      Code:
      ds = new XyzDS(this); // extends LocalDatasource
      setDataSource(ds);
      setAutoFetchData(true);
      setShowFilterEditor(true);
      setFilterOnKeypress(true);
      
      ds.reloadRecords(someNewValues);

      Comment


        #4
        Thank you to post your code! I had the same problem..

        Comment

        Working...
        X