Announcement

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

    Non-flickering Listgrid fetches

    Hi there,

    I'm currently switching my ListGrids from the current "flickery" method of updating via grid.fetchData() to the "non-flickery" way of updating, via DataSource.fetchData(crit, callback)

    But I've hit a little snag. How do I convert the callback's "Object rawData" into a Record array?

    I've read in the javadocs that:
    "In contrast to ListGrid.fetchData(), which creates a ResultSet to manage the returned data, calling dataSource.fetchData() provides the returned data in the callback as a simple JavaScript Array of JavaScript Objects."

    Any tips? I haven't played with JavaScriptObject objects before.

    Thanks!
    Alan

    #2
    It's OK, I found a previous answer you guys gave for this exact problem:

    :-)

    Originally posted by smartgwt.dev
    What you get passed back in the callback is a JS array of data records. You can do something similar to what ListGrid does to convert a native array to an array of DataClass :

    Code:
    private static DataClass[] convertToDataClassArray(JavaScriptObject nativeArray) {
            if (nativeArray == null) {
                return new DataClass[]{};
            }
            JavaScriptObject[] objs = JSOHelper.toArray(nativeArray);
            DataClass[] rows = new DataClass[objs.length];
            for (int i = 0; i < objs.length; i++) {
                JavaScriptObject rowJS = objs[i];
                DataClass row = new DataClass(rowJS);
                rows[i] = row;
            }
            return rows;
        }

    Comment


      #3
      Hi,

      This is good information, as I am also looking for a 'non-flickery' way to update the ListGrid. But, having got the array of DataClass objects, how do you then add or set them on the ListGrid? Doing a setData() disables the virtual pagination, as it then forgets what the totalRows number is.

      Thanks

      Comment


        #4
        Hi,

        You'll just need to implement pagination in a different way, and manage your own startRow, endRow, totalRows values separately. I put them in the Data Source object in my implementation.

        Alan

        Comment


          #5
          Thanks for the reply.

          Are you saying you made your own DataSource implementation, in order to control the startRow, endRow and totalRows? If so, did you subclass RestDataSource and just override getTotalRows() etc. in order to control the ListGrid pagination?

          Thanks

          Comment


            #6
            I figured out how to set records and still keep virtual pagination anyway.

            In the execute() method of a DSCallback, create a new ResultSet, and set the records on it and set it as the data like so:

            Code:
                            final ResultSet resultset = new ResultSet();
                			resultset.setDataSource(getDataSource());
                			resultset.setCriteria(request.getCriteria());
                			resultset.setInitialData(recsToDisplay);
                			resultset.setInitialLength(recsToDisplay.length);
                			setData(resultset);
            That way, it keeps the startRow, endRow and totalRows params from the DSResponse, while allowing you to set whatever records you want on the ListGrid. (The recsToDisplay, above, can be any records, not just the ones received from the data source).

            Comment

            Working...
            X