@Html.EJS().Grid("FlatGrid").DataSource((IEnumerable<object>)ViewBag.dataSource).QueryCellInfo("querycellinfo").Columns(col =>
{
col.HeaderText("Row Numer").Width("90").Add();
col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).Width("120").Add();
col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add();
col.Field("OrderDate").HeaderText("Order Date").Type("date").Width("110").Add();
col.Field("Freight").HeaderText("Freight").EditType("numericedit").Width("120").Add();
col.Field("ShipCountry").HeaderText("Ship Country").Width("150").Add();
}).AllowPaging().Render()
<script>
var count = 1;
function querycellinfo(args) {
if (args.column.headerText == "Row Numer") {
args.cell.innerHTML = count;
count++;
}
}
</script>
|
if (args.requestType == "paging" || args.requestType == "sorting" || args.requestType == "grouping" || args.requestType == "filtering" || args.requestType == "searching" || args.requestType == "close") count = 1; |
<div>
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.datasource).AllowPaging().Columns(col =>
{
col.HeaderText("RowNumber").Add();
col.Field("OrderID").HeaderText("Order ID").Add();
col.Field("EmployeeID").HeaderText("Employee ID").IsPrimaryKey(true).Add();
col.Field("ShipCountry").HeaderText("Ship Country").Add();
}).RowDataBound("rowDataBound").PageSettings(page => { page.PageSize(4); }).Render()
</div>
<script>
function rowDataBound(args) {
if (this.pagerModule.pagerObj.currentPage == 1) {
args.row.querySelector('td').innerText = +args.row.getAttribute('aria-rowindex') + 1;
}
else {
var num = (this.pagerModule.pagerObj.currentPage - 1) * this.pagerModule.pageSettings.pageSize;
args.row.querySelector('td').innerText = +args.row.getAttribute('aria-rowindex') + 1 + num;
}
}
</script>
|