EasyUI Forum
May 21, 2024, 06:35:59 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: edatagrid - working with nested JSON data  (Read 5555 times)
Stefan B.
Full Member
***
Posts: 152


Software Architekt


View Profile Email
« on: February 14, 2014, 05:53:31 AM »

Hello. I have a edatagrid and JSON data with nested field values like this:
Code:
[{"id":19,"idObject":{"systemId":"sbr_001","applicationAssignment":"Testgebiet 22","applicatioContact":"Stefan"}]

Now if i cklicked on an row to edit the data, the values of the field idObject.applicationAssignment not shown correct in the editor of the text field. The editor field are empty - why?

Update: My Test Solution:

Code:
onDblClickRow: function(rowIndex, rowData) {
  if(rowData.idObject) {
// workaround for the  value [object object] problem!
var xyzEditor = $(this).edatagrid('getEditor',{index: rowIndex, field:'idObject.applicationAssignment'});
$(xyzEditor.target).val(rowData.idObject.applicationAssignment);
  };
},

Is this correct sollution or is there a better way to do this?
« Last Edit: February 14, 2014, 06:35:46 AM by Stefan B. » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 14, 2014, 07:50:12 AM »

Please don't use the nested data on a editable data grid. It is easy to convert to normal json data by using 'loadFilter' function.
Code:
$('#dg').edatagrid({
loadFilter: function(data){
for(var i=0; i<data.length; i++){
var item = data[i];
item.systemId = item.idObject.systemId;
item.applicationAssignment = item.idObject.applicationAssignment;
//...
}
return {
total: data.length,
rows: data
}
}
})
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!