Search code examples
jqueryjsondatagridjquery-easyui

jeasyui datagrid insertrow with string format json


I am inserting a last row to a datagrid from JSON created in javascript (code copied here) I was able to produce this

 {amountA:'99,865.65', amountB:'47,781.91', amountTotal:'147,647.56'}

To insert,

function insertRow(index, thisRow) {
$("#tDataGrid").datagrid('insertRow', {
    index: index,
    row: thisRow
});

This doesn't work, but when I copied the produced JSON to the code like

     index: index,
     row:  {amountA:'99,865.65', amountB:'47,781.91', amountTotal:'147,647.56'}

it works perfectly.

What's wrong with my code? Thanks in advance.


Solution

  • Try this way to add in general

    $('#tDataGrid').datagrid({
    data: [
        {amountA:'value11', amountB:'value12', amountC:'value12'},
        {amountA:'value11', amountB:'value12', amountC:'value12'}
    ]
    });
    

    Append a new row. The new row will be added to the last position:

    $('#tDataGrid').datagrid('appendRow',{
    amountA: 123,
    amountB: 123,
    amountC: 'some Text'
    });
    

    Insert a new row at second row position.

    $('#tDataGrid').datagrid('insertRow',{
    index: 1,   // index start with 0
    row: {
        amountA: 123,
        amountB: 123,
        amountC: 'some Text'
    }
    });