Reputation: 19748
In my web-app I've got 2 ng-grids. The second is bound to the first grids selectedItems, which is working fine. The problem is I want to get the list of elements in the second grid (ideally with any sorting applied to in the second list reflected in the data) so I can submit changes to a database.
So the question is how can I access the data on the second grid, if I try:
surveyModel.surveySelectedSectionsGrid.data
I get back the string that I used to setup the grid options which says:
surveyModel.surveySectionGrid.selectedItems
What I want instead is the actual data model being used for the second grid.
Here are my two grid options definitions:
surveySectionGrid: {
data: 'surveyModel.surveySections',
multiSelect:true,
selectedItems:[],
showFilter:true,
columnDefs: [
{ field: 'name', displayName: 'Questions/Sections' },
{ field: 'sectionTypeDescription', displayName: 'Section Type' },
{ displayName: 'Edit',
field:'sectionId',
cellTemplate:'<div class="ngCellText" ng-class="col.colIndex()"><span ng-cell-text><button ng-click="gotoEditSection(row.getProperty(col.field))">Edit {{row.getProperty(col.field)}}</button></span></div>'
}
]
},
surveySelectedSectionsGrid: {
data: 'surveyModel.surveySectionGrid.selectedItems',
multiSelect:false,
selectedItems:[],
showFilter:true,
columnDefs: [
{ field: 'name', displayName: 'Selected Sections for Survey' }
]
}
Some possible ideas I've come across
The grid's rendereredRows property is an array that has entity objects that correspond to my original elements in the data but based on the name of the array it sounds like if elements are off screen they won't show up in this list.
I've found as a temporary work-around I can call selectAll(true) on my secondary grid then use the selectedItems array then call selectAll(false) but a more direct solution would be nice.
Upvotes: 2
Views: 2400
Reputation: 23
Edit: Was able to confirm OP's issue with this plnkr. If all elements are visible on an ng-grid object, renderedRows will have the correct number of elements. Otherwise, renderedRows will have < gridOptions.data.length objects to save memory.
The grid's renderedRows object should be what you're looking for. It has all the objects that are currently rendered in HTML (including those that are off screen) from the data array passed to the ng-grid object.
Source: I modified the ngGridCsvExportPlugin to only include filtered items. I used the renderedRows object and it worked like a charm. Edit: With less than 20 elements, it works well. With more than that, this solution breaks down and the best solution seems to be to use selectAll.
Hope this helps,
Brent
Upvotes: 1