سؤال

Hy guys, so my data looks like:

TimeSheetData

[
  {ID:2, Name:QXC, Items:[{Status:1, Hours: 8},{Status:1, Hours: 4}]}, 
  {ID:5, Name:ABC, Items:[{Status:1, Hours: 6},{Status:1, Hours: 0}]}
]

and my grid looks like:

  jQuery("#rowed5").jqGrid({        
    data: timeSheetData,
    datatype: "local",
    height: 250,
    colNames:['ID','Name','Monday','Tuesday'],
    colModel:[
              {name:'ContractID', index:'ContractID', jsonmap:'?????', width:200, editable:false, sortable:false},
              {name:'EmployeeName', index:'EmployeeName', jsonmap:'?????'' ,width:200, editable:false, sortable:false},
              {name:'Monday', index:'Monday', jsonmap:'?????', width:200, editable:false, sortable:false},
              {name:'Tuesday', index:'Tuesday'jsonmap:'?????'jsonmap:'timeSheetRow1.timeSheetItem2.WorkedHours', width:200, editable:false, sortable:false}
             ],
    caption: "Input Types",
    jsonReader: {repeatItems: false, root: "timeSheetRow1"}
  });

And I'm interested what in what do I need to put in place of ????? to obtain the following two rows in my jqgrid table:

   2, QXC, 8, 4
   5, ABC, 6, 0

Thx in advance!

هل كانت مفيدة؟

المحلول

So, I figured it out. My problem was that I was only looking at the object value, but not its structure. So, with that in mind the objects structure is the following:

//TimeSheetData:
var timeSheetData = new Object();
timeSheetData.Rows = [row1,row2]; /*Rows is an
Array containing Row objects*/

//Row:
var row1 = new Object();
row1.ID = 19;
row1.Name = "F.L.";
row1.Items = [item1, item2]; /*Items
is an object with containing other objects(Item) and some properties*/

//Item:
var item1 = new Object();
item1.Status = 0;
item1.Hours = 6;

So, to sum it up, the answer to my question(how does colModel look like in my situation) is:

...,
colModel:[
           {name:'ContractID', index:'ContractID', jsonmap:'ID', width:200, editable:false, sortable:false},
           {name:'EmployeeName', index:'EmployeeName', jsonmap:'Name' ,width:200, editable:false, sortable:false},
           {name:'Monday', index:'Monday', jsonmap:'Items.0.Hours', width:200, editable:false, sortable:false},
           {name:'Tuesday', index:'Tuesday', jsonmap:'Items.1.Hours', width:200, editable:false, sortable:false}
         ],
jsonReader: {repeatItems: false, root: "Rows"}
});
jQuery("#rowed5")[0].addJSONData(timeSheetData.Rows);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top