SMART datagrid v.1 > Classes > GridDataSet

Back  Forward

DataLudi.GridDataSet.insertRows  method

Insert original data of one or more data rows which are transferred by rows array in row row location of data set, and return the number of rows which have been actually inserted. 

If row is less than 0 or greater than rowCount, it will throw an exception. The data of each row which is contained in rows can be array or JSON object, and JSON object will be arranged and stored as array according to field order. 

function insertRows (row: Integer, rows: Array, start: Number, count: Number, rowEvents: Boolean): Integer;
Returns
Integer
Parameters
row - Integer. required.
rows - Array. required.
start - Number. Defaults to 0.
count - Number. Defaults to -1.
rowEvents - Boolean. Defaults to false.
If it is true, confirmation and completion events will be fired in row unit. If it is DataSet.undoable, events in row unit will not be fired regardless of this property.
Code -1
    // If rowEvents is false, the event will be fired when inserting of all rows is committed.
    ds.onRowsInserted = function (ds, row, count) {
        console.log(row + '' + count + ' row has been inserted in  th row location.';
    };
    // If rowEvents is true, the event will be fired whenever each row is inserted.
    ds.onRowInserted = function (ds, row) {
        console.log(row + 'One row has been inserted in  th row location.';
    };
    
    // Each row which is transferred by function can be array or JSON object.
    var rows = [
        ['value1', 'value2', 'value3', 111, 222],
        {
            'field1': 'value11', 
            'field2': 'value12',
            'field3': 'value13',
            'field4': 666,
            'field5': 777
        }
    ];
    // If the count is -1, it will insert all rows of rows, and if it is greater than 0, it will insert as much as Math.min(count, rows.length).
    var row = grid.focusedRowIndex();
    ds.appendRows(row, rows, 0, -1, false);
See Also
appendRows
appendRow
insertRow
Examples
Grid Data Set Edit
Row Inserting