2

在我的网络应用程序中,我有 2 个 ng-grids。第二个绑定到第一个网格 selectedItems,它工作正常。问题是我想获取第二个网格中的元素列表(理想情况下,在数据中反映的第二个列表中应用的任何排序),以便我可以将更改提交到数据库。

所以问题是如何访问第二个网格上的数据,如果我尝试:

surveyModel.surveySelectedSectionsGrid.data

我找回了我用来设置网格选项的字符串,上面写着:

surveyModel.surveySectionGrid.selectedItems

我想要的是用于第二个网格的实际数据模型。

这是我的两个网格选项定义:

    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' }
                ]
    }

我遇到的一些可能的想法

网格的 rendereredRows 属性是一个数组,其中包含与数据中我的原始元素相对应的实体对象,但根据数组的名称,如果元素不在屏幕上,它们将不会显示在此列表中。

我发现作为一种临时解决方法,我可以在我的辅助网格上调用 selectAll(true),然后使用 selectedItems 数组,然后调用 selectAll(false),但更直接的解决方案会很好。

4

1 回答 1

1

编辑:能够用这个 plnkr确认 OP 的问题。如果 ng-grid 对象上的所有元素都可见,则 renderRows 将具有正确数量的元素。否则,renderRows 将具有 < gridOptions.data.length 对象以节省内存。

网格的 renderRows 对象应该是您要查找的对象。它具有从传递给 ng-grid 对象的数据数组中当前以 HTML 呈现的所有对象(包括那些不在屏幕上的对象)。

来源:我将 ngGridCsvExportPlugin 修改为仅包含过滤后的项目。我使用了 renderRows 对象,它就像一个魅力。编辑:少于 20 个元素,效果很好。不仅如此,这个解决方案就失效了,最好的解决方案似乎是使用 selectAll。

希望这可以帮助,

布伦特

于 2013-07-19T18:37:45.853 回答