使用 GroupingStore 上的分组重新配置 GridPanel

发布于 2024-10-19 23:41:33 字数 1470 浏览 1 评论 0原文

我对使用 GroupingView 的 GridPanel 遇到问题:

var grid1 = new Ext.grid.GridPanel({
    store: new Ext.data.GroupingStore({
        fields: [ ]
    }),
    cm: new Ext.grid.ColumnModel([  ]),
    selModel: new Ext.grid.RowSelectionModel({ singleSelect: false }),
    view: new Ext.grid.GroupingView({
        groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "' + BPS.Resource.items + '" : "' + BPS.Resource.item + '"]})'
    })
});

我调用重新配置的事件来设置新的存储和列模型。该商店是一个 GroupingStore,我设置了要使用的 groupField:

// define the store
var store1 = new Ext.data.GroupingStore({
    proxy: new Ext.data.HttpProxy({
        url: listConfig.dataURL + '?sort=' + listConfig.defaultSortField + '&dir=' + listConfig.defaultSortDirection,
        method: 'POST'
    }),
    autoLoad: false,
    remoteSort: true,
    remoteGroup: true,
    groupOnSort: false,
    groupField: listConfig.groupingColumn,
    sortInfo: {
        field: listConfig.defaultSortField,
        direction: listConfig.defaultSortDirection
    },
    paramNames: {
        start: 'skip',
        limit: 'take',
        sort: 'sort',
        dir: 'dir'
    },
    reader: new Ext.data.JsonReader()
});

// reconfigure the grid
grid1.reconfigure(store1, new Ext.grid.ColumnModel(listConfig.columnDefinitions));

但是,这似乎在第一次加载时起作用。它会在一列上设置分组,或者如果我没有配置它,则根本不进行分组。但是,当用户关闭网格面板中的分组并且运行相同的代码以加载配置后,它不会将其更改为分组。

我可以做什么来重新配置网格以使用或不使用分组?

I have a problem with a GridPanel that uses a GroupingView:

var grid1 = new Ext.grid.GridPanel({
    store: new Ext.data.GroupingStore({
        fields: [ ]
    }),
    cm: new Ext.grid.ColumnModel([  ]),
    selModel: new Ext.grid.RowSelectionModel({ singleSelect: false }),
    view: new Ext.grid.GroupingView({
        groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "' + BPS.Resource.items + '" : "' + BPS.Resource.item + '"]})'
    })
});

I an event I call reconfigure that sets a new store and columnmodel. The store is a GroupingStore and I set what groupField i want to use:

// define the store
var store1 = new Ext.data.GroupingStore({
    proxy: new Ext.data.HttpProxy({
        url: listConfig.dataURL + '?sort=' + listConfig.defaultSortField + '&dir=' + listConfig.defaultSortDirection,
        method: 'POST'
    }),
    autoLoad: false,
    remoteSort: true,
    remoteGroup: true,
    groupOnSort: false,
    groupField: listConfig.groupingColumn,
    sortInfo: {
        field: listConfig.defaultSortField,
        direction: listConfig.defaultSortDirection
    },
    paramNames: {
        start: 'skip',
        limit: 'take',
        sort: 'sort',
        dir: 'dir'
    },
    reader: new Ext.data.JsonReader()
});

// reconfigure the grid
grid1.reconfigure(store1, new Ext.grid.ColumnModel(listConfig.columnDefinitions));

However, this seem to work the first time it's loaded. It sets grouping on a column, or no grouping at all if I haven't configured it. But after the user turn off grouping in the gridpanel and the same code runs in order to load the configuration it doesn't change it to be grouped.

What can I do to reconfigure the grid to use, or not use, grouping?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬花如无物 2024-10-26 23:41:33

我在使用分组商店时遇到了问题。当我修改记录的字段并且分组位于我修改字段的那一列上时,网格不会自动重新分组记录。
此外,在添加新行时,分组不正确,添加的记录未添加到正确的组中。

我通过将当前的 groupBy 字段保留在全局变量中解决了这个问题,每次更新或编辑后,并从网格中添加事件,我取消分组,然后将 groupBy() 与包含商店分组的当前列的变量一起使用。

仅使用 grid.getView().refresh();没有成功。

当然问题是,这个用户友好吗?因为每次修改行中的字段并且在修改的字段的列上设置分组时,记录都会重新分组,并且用户可能无法找到他正在修改的行。

更好的解决方案:当正在编辑的记录上的焦点丢失时,仅取消分组,然后将 groupBy() 与存储当前 groupBy 列的 var 一起使用。关于模糊事件也是如此。

I was having issues with a groupingstore. When I modified a field of a record and the grouping was on that column where I modified the field from, the grid did not automatically regroup the records.
Also when adding a new row, the grouping was not correct, the record that was added did not get added in the correct group.

I solved this problem by keeping the current groupBy field in a global var and each time on update or afteredit and added events from the grid I unGrouped and then used groupBy() with the var that contains the current column where the store was grouped on.

Using only grid.getView().refresh(); didn't do the trick.

Question of course is, is this user friendly? Because each time that a field from a row is modified and the grouping is set on the column of that field that was modified, the record will get regrouped and the user might have problems finding the row he was modifying.

Better solution: Only unGroup and then use groupBy() with the var that stored the current groupBy column when the focus on the record that is being edited is lost. SO on the blur event.

爱给你人给你 2024-10-26 23:41:33

我认为您将一个侦听器附加到 GroupingStore 的 groupchange 事件并记录被选为分组字段的字段。然后,在重新配置时,您可以使用 groupBy() 函数告诉商店按该字段进行分组,或者使用 ungroup() 函数删除分组。然后调用网格视图的refresh()方法。

请注意,我还没有测试过这个,所以它可能完全是垃圾! :-)

I think you attach a listener to the GroupingStore's groupchange event and record the field that was chosen as the grouping field. Then when reconfiguring, you tell the store to group by that field with the groupBy() function or use the ungroup() function to remove the grouping. Then call the grid's view refresh() method.

Note that I haven't tested this so it may be complete rubbish! :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文