jQWidgets Forums
jQuery UI Widgets › Forums › Grid › How to map grid datafields to child observable array
This topic contains 7 replies, has 4 voices, and was last updated by Peter Stoev 9 years, 10 months ago.
-
Author
-
Hi!
I have observable array that has child array. Something like
testArray {property1 = ko.observable(),property2 = ko.observable(),childArray = ko.observableArray()}
How can I map observable childArray items (childArray [0], childArray [1], etc) in the following code?
var typeSource = { localdata: viewModel.testArray, datatype: 'observablearray', datafields: [ { name: 'property1' }, { name: 'property2' }, { name: 'childArray ()[0] ' } ???????????? ] }
I did not find example of this in demo projects.
Thanks!
P.S. My code uses jqxDataAdapter
Hi isv485,
The “name” field expects a string. It is not possible to use it for nested observables.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHas there been any more development on this by chance? I have a nested observable array as well in Knockout that I need to bind to the grid, and I’m not sure how to set up the map property for that.
Hi Simon,
As far as I know, there are no changes about that.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comAny chance in the near future for an enhancement, which covers the mapping of an observable childarray?
Maybe a workaround besides creating computed properties with every object from the array on the childarrays parent?
data=[{FacultyName:’Abc’, AverageGrade:nr, Students:[{Name:’John Doe’, Grade:4}, {Name:’John Smith’, Grade:5}]},
{FacultyName:’Xyz’, AverageGrade:nr2, Students[]}]where data and Students are observable arrays.
I’ve tried to map like
datafields: [
{ name: ‘Grades’, map: ‘Students> 0 > Grade’ },
]
But it doesn’t work as intended.
I was also wondering if its possible to index dynamically somehow?Hi monica.moga,
In your case, you should map to Students and then display their Names and Grades in the Grid. You shouldn’t map to sub settings of a Students array.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
Sorry, i’m not sure if I fully understand your suggestion.
I need in the same grid columns from both levels:
FacultyName | AverageGrade| Grade1| Grade2| …where Grade1 would need to be the datafield mapped like : “Students > 0 > Grade” and Grade2 a similar one “Students > 1 > Grade”
Do you suggest something like this?
datafields:[{name:’Student1′, map:”Students>0″},{name:”Grade1″,map:”Student1>Grade”}]
and then use Grade1 datafield to the corresponding column? -> I don’t see any difference between the 2, except that the mapping is split in two.
If not, i would be grateful for a bit more detailed explanation.Hi monica.moga,
You cannot display a Hierarchical Data structure in a Flat table. You have subarray with Students per Faculty Name. If you want to display such structures you should consider using other widget like TreeGrid.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com -
AuthorPosts
You must be logged in to reply to this topic.