gpt4 book ai didi

javascript - kendo ui 网格分组不区分大小写

转载 作者:行者123 更新时间:2023-11-30 06:29:58 25 4
gpt4 key购买 nike

我正在尝试使用剑道网格进行分组,但我遇到了剑道分组默认功能的问题。 Kendo 网格对列进行分组,但它不会区分“USA”和“usa”的记录,这些记录带有两个不同的分组记录集。 “Washington”和“Washington”等国家或名称也是如此。我想要一个不区分大小写的分组(“USA”和“usa”在逻辑上除了它们的大小写之外意思相同),任何人都知道如何做。我在剑道文档的任何地方都找不到这个。

这是我的代码片段。

Maplytics_jQ19("#grdData").kendoGrid(
{
editable: false,
sortable: true,
filterable: true,
//dataSource: _recordsInGrid,
groupable: true,
dataSource: {
data: _recordsInGrid,
group: { field: groupingField }
},
reorderable: true,
resizable: true,
dataBound: onDataBound,
selectable: false,
columns: columns,
schema: {
data: "_recordsInGrid"
},
scrollable: true
}
);

最佳答案

我重写了 Kendo.data.QUery 中的 groupBy 方法,它起作用了:

    function groupValueComparer(a, b) {
if (a && a.getTime && b && b.getTime) {
return a.getTime() === b.getTime();
}
if (typeof a == "string" && typeof b == "string") {
return a.toLowerCase() == b.toLowerCase();
}
return a === b;
}
var isEmptyObject = $.isEmptyObject;

kendo.data.Query.prototype.groupBy = function(descriptor) {
if (isEmptyObject(descriptor) || !this.data.length) {
return new Query([]);
}

var field = descriptor.field,
sorted = this._sortForGrouping(field, descriptor.dir || "asc"),
accessor = kendo.accessor(field),
item,
groupValue = accessor.get(sorted[0], field),
group = {
field: field,
value: groupValue,
items: []
},
currentValue,
idx,
len,
result = [group];

for(idx = 0, len = sorted.length; idx < len; idx++) {
item = sorted[idx];

currentValue = accessor.get(item, field);
if(!groupValueComparer(groupValue, currentValue)) {
groupValue = currentValue;
group = {
field: field,
value: groupValue,
items: []
};
result.push(group);
}
group.items.push(item);
}
return new kendo.data.Query(result);
}

link demo

关于javascript - kendo ui 网格分组不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18316136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com