DevExtreme DataGrid:从Lookup数据源取筛选选项而非请求服务器
解决方案:让DevExtreme DataGrid筛选行使用本地Lookup数据源(避免远程请求)
当开启remoteOperations: true时,DataGrid默认会让筛选行的Lookup编辑器发起远程请求获取选项。要让筛选行直接使用本地已有的Lookup数据源,需在编辑器准备阶段强制替换数据源并禁用远程操作,具体实现如下:
修改核心代码
重点调整onEditorPreparing事件处理逻辑,针对筛选行的Lookup列单独配置本地数据源:
onEditorPreparing: function (e) { if (e.parentType === "filterRow") { switch(e.dataField) { case "channelId": // 强制筛选行使用本地_channels数据源,禁用远程操作 e.editorOptions.dataSource = { store: _channels, remoteOperations: false }; // 保留status列的联动逻辑,同时确保status数据源也用本地数据 e.editorOptions.onValueChanged = function (arg) { filterEditor.option("dataSource", { store: _statuses, filter: ["channelId", "=", arg.value], remoteOperations: false }); e.setValue(arg.value); }; break; case "status": // 筛选行的status编辑器默认使用本地_statuses数据源 e.editorOptions.dataSource = { store: _statuses, remoteOperations: false }; break; case "statusGroup": // 强制筛选行使用本地_statusGroups数据源,禁用远程操作 e.editorOptions.dataSource = { store: _statusGroups, remoteOperations: false }; break; } } },
关键修改说明
- 对每个筛选行的Lookup列,明确指定
dataSource为本地已有的store(_channels、_statuses、_statusGroups),并设置remoteOperations: false,彻底阻断远程请求。 - 对于依赖其他列的
status列,在channelId的联动逻辑中,更新filterEditor数据源时同样加上remoteOperations: false,确保联动后依然使用本地数据筛选。 - 单元格编辑时的Lookup逻辑不受影响,依然保持原有动态筛选行为。
内容的提问来源于stack exchange,提问作者eltano
相关产品推荐
相关产品推荐

