The loadFilter
function of datagrid can convert any data to the standard data format that can be loaded into datagrid.
<script>
var data = { "ROWCOUNT":83
, "COLUMNS":["CUSTOMERID","CUSTOMERFIRSTNAME"]
, "DATA":{
"CUSTOMERID":[101,102]
,"CUSTOMERFIRSTNAME":["Bhavin","Frank"]
}
};
function myLoadFilter(data){
var result = {total:data.ROWCOUNT};
var rows = [];
var count = data.DATA[data.COLUMNS[0]].length;
for(var i=0; i<count; i++){
var row = {};
$.map(data.COLUMNS, function(field){
row[field] = data.DATA[field][i];
})
rows.push(row);
}
result.rows = rows;
return result;
}
</script>
The datagrid component can be declared as:
<table class="easyui-datagrid" title="Basic DataGrid" style="width:700px;height:250px"
data-options="
singleSelect:true,
collapsible:true,
data:data,
loadFilter:myLoadFilter
">
<thead>
<tr>
<th data-options="field:'CUSTOMERID',width:100">CUSTOMERID</th>
<th data-options="field:'CUSTOMERFIRSTNAME',width:200">CUSTOMERFIRSTNAME</th>
</tr>
</thead>
</table>
The example is available from http://jsfiddle.net/d8zYy/