easyui datagrid某些行不参与排序
时间: 2023-08-12 07:11:05 浏览: 59
您可以通过重写 easyui datagrid 的排序函数来实现某些行不参与排序,具体步骤如下:
1. 在 easyui datagrid 的初始化函数中添加 onSortColumn 事件处理函数,该函数用于重写排序函数:
```
$('#datagrid').datagrid({
...
onSortColumn: function (sort, order) {
var rows = $('#datagrid').datagrid('getRows');
rows = rows.filter(function(row) {
// 过滤掉不需要参与排序的行
return row.id !== 1 && row.id !== 3;
});
rows.sort(function(a, b) {
// 在这里实现您自己的排序逻辑
return a[sort] > b[sort] ? order === 'asc' ? 1 : -1 : order === 'asc' ? -1 : 1;
});
// 将过滤后的行重新渲染到 datagrid 中
$('#datagrid').datagrid('loadData', rows);
},
...
});
```
2. 在排序函数中,使用 filter 函数过滤掉不需要参与排序的行,然后再使用 sort 函数对剩余的行进行排序。
3. 最后,使用 loadData 函数将排序后的行重新渲染到 datagrid 中。
需要注意的是,排序函数中的 row.id !== 1 && row.id !== 3 是一个示例,您需要根据您自己的需求来编写过滤条件。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)