<div id="Grid"></div> <script type="text/javascript"> $(function () { $("#Grid").ejGrid({ dataSource: window.gridData, allowPaging: true, allowSorting: true, allowFiltering: true, allowGrouping: true, actionBegin: function (args) { if (this.model.groupSettings.groupedColumns.indexOf("CustomerID") != -1) { //for grouping var cols = this.model.sortSettings.sortedColumns; if (!ej.DataManager(cols).executeLocal(new ej.Query().where("field", "equal", "Freight")).length) this.model.sortSettings.sortedColumns.push({ field: "Freight", direction: "descending" }) } else if (args.requestType == "ungrouping" && args.columnName == "CustomerID") { //for ungrouping var cols = this.model.sortSettings.sortedColumns; var index = cols.indexOf(ej.DataManager(cols).executeLocal(new ej.Query().where("field", "equal", "Freight"))[0]); this.model.sortSettings.sortedColumns.splice(index, 1) } }, groupSettings: { groupedColumns: ["CustomerID"] }, columns: [ { field: "CustomerID", headerText: "Customer" }, { field: "Freight", headerText: "Total Amount", format: "{0:C}" } ] }); }); </script> |