EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: frankgao on May 19, 2016, 07:17:32 AM



Title: How to updateRow datagrid cell value by variable name?
Post by: frankgao on May 19, 2016, 07:17:32 AM
Datagrid hava 4 cell field,1 row.
I need set the same value.but if var name='name'+i; the value no change.
 
Code:
 function  setInitValue(){
 
  for(var i=0;i<5;i++){
    var name='name'+i;
    $('#dg').datagrid('beginEdit', 0);
    $('#dg').datagrid('updateRow',{
                                    index:0,
                                    row:{
                                        name:'My name is frank'
                                    }
                                });
                                $('#name').datagrid('endEdit', 0); 
   
  }
    $('#dg').datagrid('acceptChanges');
 }



Code:
{ field: 'name0', title: 'Name0', width: '120px', sortable: true },
{ field: 'name1', title: 'Name1', width: '120px', sortable: true },
{ field: 'name2', title: 'Name2', width: '150px', sortable: true },
{ field: 'name3', title: 'Name3', width: '150px', sortable: true },
{ field: 'name4', title: 'Name4', width: '150px', sortable: true },


Title: Re: How to updateRow datagrid cell value by variable name?
Post by: stworthy on May 19, 2016, 11:53:49 PM
Please try this code instead.
Code:
var row = {};
for(var i=0; i<5; i++){
row['name'+i] = 'My name is frank';
}
$('#dg').datagrid('updateRow', {
index:0,
row:row
});