Child pages
  • Refresh ListGrid Periodically (SmartClient)

Versions Compared

Key

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

...

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

Code Block
languagejs
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 selectedRows = supplyItemListGrid.getSelectedState() 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);
    supplyItemListGrid.setSelectedState(selectedRows);
};};

    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