@(Html.EJ().Grid<object>("FlatGrid")
. . . .
.ClientSideEvents(eve=>eve.ActionBegin("actionBegin").ActionComplete("actionComplete"))
)
<script type="text/javascript">
function actionBegin(args) {
if (args.requestType == "sorting" && args.columnName == "Grade.Display") {
var sortCol = args.model.sortSettings.sortedColumns;
sortCol[sortCol.length - 1]["field"] = "Grade.Value";//update the sortedColumn field to "Grade.Value"
}
}
function actionComplete(args) {
if (args.requestType == "sorting" && args.columnName == "Grade.Display") {
//code to update the sort icon in header
var index = this.getColumnIndexByField(args.columnName);//get the column index
//get the headerCellDiv element
var $headerCellDiv = this.getHeaderTable().find("thead tr:not('.e-stackedHeaderRow')").find(".e-headercell").not(".e-detailheadercell").eq(index).find(".e-headercelldiv");
var direction = args.columnSortDirection;//get the sorting direction
var spantag = ej.buildTag('span.e-icon', " ");
$headerCellDiv.find(".e-ascending,.e-descending").remove();//remove the previously appended icons from the headercellDiv
imageDirection = direction != "descending" ? "e-rarrowup-2x" : "e-rarrowdown-2x";
$headerCellDiv.append(spantag.addClass("e-" + (direction || "ascending") + " " + imageDirection));//append the sort icon
}
}
</script> |