ExtJS网格中的重复列标题冲突

时间:2017-04-25 09:34:14

标签: extjs grid duplicates extjs4

我想要一个允许重复列名的网格,但要包含不同的数据。显然这会导致冲突,具有重复名称的列只会复制第一列中的数据并移动其他数据。

这就是我的意思。我有一个专栏" FirstName"我想重命名为"登录": enter image description here

我将其重命名,但是"登录"已经存在并且会发生这种情况:

enter image description here

我的商店动态添加到网格中:

var columnNames = ["RecordID", "RowDateModified", "Login", "ActionType", "DateModified", "RawDataSetSyncDiscardedType", "ID", "FirstName", "LastName", "Email", "Gender"]
var myData = [["3000010032", "2017-04-25 09:11:47.2600000", "Administrator", "I", "2017-04-25 09:11:47.3570000", "COMMITTED", "3", "Lawrence", "Stone", "lstone2@toplist.cz", "Male"],["3000010033", "2017-04-25 09:11:47.2600000", "Administrator", "I", "2017-04-25 09:11:47.3570000", "COMMITTED", "2", "Karen", "Dean", "kdean1@ovh.net", "Female"],["3000010034", "2017-04-25 09:11:47.2600000", "Administrator", "I", "2017-04-25 09:11:47.3570000", "COMMITTED", "4", "Marie", "Carter", "mcarter3@jiathis.com", "Female"],["3000010035", "2017-04-25 09:11:47.2600000", "Administrator", "I", "2017-04-25 09:11:47.3570000", "COMMITTED", "6", "Lawrence", "Richardson", "lrichardson5@ovh.net", "Male"]]

dataStore = Ext.create('Ext.data.ArrayStore', {
fields: columnNames,
data: myData
});

for (var i = 0; i < columnNames.length; i++) {
columnsArr.push({
    text: columnNames[i],
    sortable: true,
    forceFit: true,
    minWidth: 150,
    dataIndex: columnNames[i]
});
}

grid.reconfigure(dataStore, columnsArr);
编辑:columnNamesmyData是动态生成的。当我重命名列时,重命名函数返回不同的columnNames数组。

我怀疑这是ExtJS问题,但是不能在表格中使用重复的名称是没有意义的。

我的问题是我做错了什么(比如错过房产)或者我应该采取一些解决方法来解决这个问题?

我正在使用ExtJS 4.0.7

1 个答案:

答案 0 :(得分:1)

ExtJS使用dataIndex字段将您的数据绑定到您的列。但是您为两列设置了相同的dataIndex。这就是为什么你的两列中有相同数据的原因。

只需使用一个数组设置列的text,另一个设置dataIndex

var columnNames = ["RecordID", "RowDateModified", "Login", "ActionType", "DateModified", "RawDataSetSyncDiscardedType", "ID", "Login", "LastName", "Email", "Gender"];
var columnDataIndexes = ["RecordID", "RowDateModified", "Login", "ActionType", "DateModified", "RawDataSetSyncDiscardedType", "ID", "FirstName", "LastName", "Email", "Gender"]
var myData = [["3000010032", "2017-04-25 09:11:47.2600000", "Administrator", "I", "2017-04-25 09:11:47.3570000", "COMMITTED", "3", "Lawrence", "Stone", "lstone2@toplist.cz", "Male"],["3000010033", "2017-04-25 09:11:47.2600000", "Administrator", "I", "2017-04-25 09:11:47.3570000", "COMMITTED", "2", "Karen", "Dean", "kdean1@ovh.net", "Female"],["3000010034", "2017-04-25 09:11:47.2600000", "Administrator", "I", "2017-04-25 09:11:47.3570000", "COMMITTED", "4", "Marie", "Carter", "mcarter3@jiathis.com", "Female"],["3000010035", "2017-04-25 09:11:47.2600000", "Administrator", "I", "2017-04-25 09:11:47.3570000", "COMMITTED", "6", "Lawrence", "Richardson", "lrichardson5@ovh.net", "Male"]]

dataStore = Ext.create('Ext.data.ArrayStore', {
fields: columnDataIndexes,
data: myData
});

for (var i = 0; i < columnNames.length; i++) {
columnsArr.push({
    text: columnNames[i], // <<== Column names array
    sortable: true,
    forceFit: true,
    minWidth: 150,
    dataIndex: columnDataIndexes[i] // <<== Different array here (dataIndexes)
});
}

grid.reconfigure(dataStore, columnsArr);