EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: BinaryCode on June 30, 2015, 04:21:58 PM



Title: Find Datagrid Record and Update
Post by: BinaryCode on June 30, 2015, 04:21:58 PM
Hello,

I have datagrid like this:

Code:
<table class="easyui-datagrid" style="width:400px;height:250px"
        data-options="url:'datagrid_data.json',fitColumns:true,singleSelect:true">
    <thead>
        <tr>
            <th data-options="field:'id',width:100">ID</th>
            <th data-options="field:'name',width:100">Name</th>
            <th data-options="field:'price',width:100,align:'right'">Price</th>
        </tr>
    </thead>
</table>

Is possible find datagrid recording by id, and update record onthefly without reload again?

TIA


Title: Re: Find Datagrid Record and Update
Post by: stworthy on July 01, 2015, 01:42:06 AM
You have to find the record by yourself. After that, call 'getRowIndex' method to get the row index and then call 'updateRow' method to update that row.

Code:
var dg = $('#dg');
var row = null;
var rows = dg.datagrid('getRows');
for(var i=0,len=rows.length; i<len; i++){
    if (rows[i]['itemid'] == 'EST-11'){
        row = rows[i];
        break;
    }
}
if (row){
    var index = dg.datagrid('getRowIndex', row);
    dg.datagrid('updateRow', {
        index: index,
        row: {
            attr1: 'updated Attribute'
        }
    })
}


Title: Re: Find Datagrid Record and Update
Post by: BinaryCode on July 01, 2015, 03:51:31 PM
Hi stworthy,

Very help me,

TIA,