EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: sushy on February 19, 2014, 10:30:16 PM



Title: Fix the datagrid header row when sort
Post by: sushy on February 19, 2014, 10:30:16 PM
Hi,

I want Fix one header row at row 1.
It is easy to sort data from remote, only need  to response the header row to the first row . But how can I show it at row 1 if to sort data form locale.

(http://www.readclub.net/2014/img/4.jpg)


Title: Re: Fix the datagrid header row when sort
Post by: stworthy on February 20, 2014, 12:30:15 AM
To freeze a specified row on top of grid after sorting the grid, please move that row to first position in 'onSortColumn' event handler.
Code:
<script>
function onSortColumn(){
var dg = $(this);
var index = -1;
var rows = dg.datagrid('getRows');
for(var i=0; i<rows.length; i++){
var row = rows[i];
if (row.itemid == 'ItemHeader'){
index = i;
break;
}
}
if (index >= 0){
var row = rows[index];
dg.datagrid('deleteRow', index);
dg.datagrid('insertRow', {
index: 0,
row: row
});
dg.datagrid('freezeRow', 0);
}
}
$(function(){
    $('#dg').datagrid({onSortColumn:onSortColumn});
});
</script>


Title: Re: Fix the datagrid header row when sort
Post by: sushy on February 20, 2014, 01:44:55 AM
Great! So good! Thank you!