2013-08-19 34 views
2

我试图用kendo网格进行分组,但是我正面临着kendo分组默认功能的问题。剑道网格对这些列进行分组,但它不会将“美国”与“美国”的记录区分开来,这些记录带有两组不同的分组记录。国家或“华盛顿”和“华盛顿”这样的名字也是如此。我想有一个不区分大小写的分组(“USA”和“usa”意思是与他们的情况逻辑上相同),任何人都有关于如何去做的想法。我在kendo文档的任何地方都找不到这个。kendo ui网格分组不区分大小写

这是我的代码片段。

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 
         } 
         ); 

回答

0

我重写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