@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").Width("120").IsPrimaryKey(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("CustomerID").HeaderText("Order Date").Width("130").SortComparer("sortComparer").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
}).Height("400").AllowPaging().Toolbar(new List<string>
() { "Add", "Edit", "Delete", "Update", "Cancel" }).AllowSorting(true).AllowFiltering().FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)).EditSettings(edit => { edit.AllowEditing(true).AllowAdding(true).AllowDeleting(true); }).Render()
</div>
<script type="text/javascript">
function sortComparer(reference, comparer, refrenceObj, comparerObj) {
var refC = parseInt(reference.replace(" Days Ago", ""));
var comC = parseInt(comparer.replace(" Days Ago", ""))
if (refC < comC) {
return -1;
}
if (refC > comC) {
return 1;
}
return 0;
}
</script> |
public void BindData()
{
int code = 10000;
for (int i = 1; i < 10; i++)
{
orddata.Add(new OrdersDetails(code + 2, "293 Days Ago", i + 0, 3.3 * i, true, new DateTime(1995, 7, 2, 2, 3, 5), "Madrid", "Queen Cozinha", "Brazil", new DateTime(1996, 9, 11), "Avda. Azteca 123"));
orddata.Add(new OrdersDetails(code + 3, "292 Days Ago", i + 1, 4.3 * i, true, new DateTime(2012, 12, 25, 2, 3, 5), "Cholchester", "Frankenversand", "Germany", new DateTime(1996, 10, 7), "Carrera 52 con Ave. Bolívar #65-98 Llano Largo"));
orddata.Add(new OrdersDetails(code + 4, "288 Days Ago", i + 2, 5.3 * i, false, new DateTime(2002, 12, 25, 2, 3, 5), "Marseille", "Ernst Handel", "Austria", new DateTime(1996, 12, 30), "Magazinweg 7"));
orddata.Add(new OrdersDetails(code + 5, "1289 Days Ago", i + 3, 6.3 * i, true, new DateTime(1953, 02, 18, 05, 2, 4), "Tsawassen", "Hanari Carnes", "Switzerland", new DateTime(1997, 12, 3), "1029 - 12th Ave. S."));
code += 5;
}
}
|
var direction;
function actionBegin(args) {
if (args.requestType === 'sorting') {
direction = args.direction; // you can get sort direction using this code..
}
}
function sortComparer(reference, comparer, refrenceObj, comparerObj) {
console.log(direction);
. . . . . . .
}
|