我有一个剑道网格,希望某些行在排序后保持固定在网格顶部。我可以通过在每列上指定自定义排序来实现。例如:
<script>
var ds = new kendo.data.DataSource({
data: [
{ name: "Jane Doe", age: 30, height: 170, pinToTop: false },
{ name: "John Doe", age: 33, height: 180, pinToTop: false },
{ name: "Sam Doe", age: 28, height: 185, pinToTop: true },
{ name: "Alex Doe", age: 24, height: 170, pinToTop: false },
{ name: "Amanda Doe", age: 25, height: 165, pinToTop: true }
]
});
$('#grid').kendoGrid({
dataSource: ds,
sortable: {mode: 'single', allowUnsort: false},
columns: [{
field: "name",
title: "Name",
sortable: {
compare: function (a, b, desc) {
if (a.pinToTop && !b.pinToTop) return (desc ? 1 : -1);
if (b.pinToTop && !a.pinToTop) return (desc ? -1 : 1);
if (a.name > b.name) return 1;
else return -1;
}
}
}
//Other columns would go here
]
});
</script>
当用户通过单击列标题对网格进行排序时,这可以很好地工作。但是,如果我想使用Javascript代码对网格进行排序,如下所示:
$('#grid').data('kendoGrid').dataSource.sort({field: 'age', dir: 'asc'});
该pinToTop
字段将被忽略。这是因为排序是在DataSource上执行的,但是自定义排序逻辑是网格的一部分。
我需要:
或者:
这不是我想要的,但是我能够通过对多个字段进行排序并pinToTop
首先包括该字段来解决此问题:
$('#grid').data('kendoGrid').dataSource.sort([{field: 'pinToTop', dir: 'desc'},{field: 'age', dir: 'asc'}]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句