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.

...

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

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