Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Description

ListGrid displays a list of objects in a grid, where each row represents one object and each cell in the row represents one property.

Periodical updating ListGrid is possible in the following ways:

  • Use Using the invalidateCache method. It update  method. This approach updates the data and will show a loading message and . However, this API will disrupt the existing view.
  • Transparent update by by DataSource using  using the fetchData method. It update the data will not  method. This method updates the data but doesn't show a loading message and will not won't disrupt the existing view.

...

Transparent update

For transparent loading of the data the fetchData method should be used fetchData method.

Code Block
langlanguagejavascriptjs
titleUpdate by DataSource
langjavascript
firstline1
linenumberstrue
var onRefresh = function() {

    var dataSource = supplyItemListGrid.getDataSource();
    var visibleRows = supplyItemListGrid.getVisibleRows();

    // request = { one page's worth of data on either side of the current viewport
    var startRow: = visibleRows[0] - supplyItemListGrid.data.resultSize,
    	endRow: (supplyItemListGrid.getVisibleRows() = visibleRows[1] + supplyItemListGrid.data.resultSize;

    if (startRow < 0) {
		startRow = 0;
	}

    var request = {
        startRow: startRow,
        endRow: endRow,
        sortBy: supplyItemListGrid.getSort(),
        showPrompt: false
    };

    var callback = function(dsResponse,data,dsRequest) {

        var result = dsResponse.data,
    	initialData = [];

    	// correctly position the result in the resultset's cache 
        initialData.length = dsResponse.totalRows;

        copyArray(result, initialData, dsResponse.startRow);

        var resultSet = isc.ResultSet.create({
            dataSource: supplyItemListGrid.getDataSource(),
            initialLength: dsResponse.totalRows,
            initialData: dsResponse.data,initialData, 
            sortSpecifiers: supplyItemListGrid.getSort(),
            criteria: supplyItemListGrid.getCriteria()
        });

        supplyItemListGrid.setData(resultSet);
    };

    dataSource.fetchData(supplyItemListGrid.getCriteria(), callback, request);
}

// copy all elements from the src array to the dest array, beginning at startPos
function copyArray(src, dest, startPos) {
	start = start || 0;
	for (var i=0; i < src.length; i++) {
		dest.set(start + i, src.get(i));
	}
}

Attachments

Attachments