You can set or change the size of the data set by calling GridDataSet.setRowCount in advance. At this point, you can empty the values of the added row. In other words, no actual value may be in the rows of GridDataSet, and you can fill them with values through updateRow or updateRows in an appropriate time after specifying rowCount.
If use setRowCount, you can implement an appropriate UI in the case of massive data or narrow network bandwidth. You can check whether the actual value has been initialized in each row through hasData method. In the example below, it sets the number of empty rows as 5 and fills values in 0, 2, 4 rows by calling DataSet.updateRow.
Check whether the value of Focused Row has been initialized.
btnCheckRow_click: function () {
var row = grdMain.focusedDataRowIndex();
if (row >= 0) {
alert(dsMain.hasData(row) ? 'Value exists' : 'No value');
}
}
Check again after updating the value of the empty row.
You can specify the initial value and the row state by calling GridDataSet. In the grid below, it increases rowCount by 2 rows according to the settings.
If fillDefaults and defaultValues of setRowCount are all specified and the corresponding field value of defaultValues is not undefined, it will be initialized to the value of defautlValues rather than the default value of the field.
In the example below, it presets rowCount as 1000 and fills values in each 5 rows asynchronously with using setTimeout.
btnRun_click: function () {
dsMain3.setRowCount(1000);
for (var i = 0; i < 200; i++) {
(function (start) {
setTimeout(function () {
var rows = [];
for (var r = 0; r < 5; r++) {
rows.push(['aaa', 'bbb', start + r, 'ccc']);
}
dsMain3.updateRows(start, rows);
}, Math.random() * 10000);
})(i * 5);
}
}