|
@(Html.EJ().Grid<Object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.DataSource)
----
.ClientSideEvents(eve => { eve.ActionBegin("GridActionBeginEvent").ActionComplete("GridActionCompleteEvent"); })
.Columns(col =>
{
col.Type("checkbox").Width(80).Add();
----
})
)
</div>
</div>
<script type="text/javascript">
var rec = [];
// action complete event when we do for filtering
function GridActionCompleteEvent(args) {
if (args.requestType == "filtering") { // Check the condition
var data = this.model.currentViewData, len = this.model.currentViewData.length, arrayLength = primaryKeyValuesArray.length;
for (j = 0; j < len; j++) {
for (k = 0; k < arrayLength; k++) {
var value = data[j]["OrderID"]; //Get the value of primary key when we virtual scrolling
if (value == primaryKeyValuesArray[k]) { // Check the stored records primary key values and currnet view data primary key value
this.multiSelectCtrlRequest = true;
this.selectRows(j); //Select the row using selectRows method
this.getSelectedRows().find("input").attr('checked', true);
}
}
}
}
}
// Action begin event when do for filtering
function GridActionBeginEvent(args) {
if (args.requestType == "filtering") {// Check the condition
debugger
var check = this.checkSelectedRowsIndexes; // collection which holds the page index and the selected record index
if (check.length) {
for (var pageInx = 0; pageInx < check.length; pageInx++) {
if (!ej.isNullOrUndefined(check[pageInx]))
rec = getRecords(pageInx, check[pageInx], this, rec);
}
}
var selectedRecords = rec;
var length = rec.length; //Get the currently selectedRecords and length using getSelectRecords method.
primaryKeyValuesArray = []; // Create a global array for future use
for (i = 0; i < length; i++) {
var value = selectedRecords[i]["OrderID"]
primaryKeyValuesArray.push(value); //Push the primary key values of currently selected records
}
}
}
// to get the selected record in all pages
function getRecords(pageInx, inx, proxy, rec) {
if (inx.length) {
for (var i = 0; i < inx.length; i++) {
var pageSize = proxy.model.pageSettings.pageSize; //gets the page size of grid
var data = proxy.model.dataSource[pageInx * pageSize + inx[i]];
rec.push(data); //pushing all the selected Records
}
}
return rec;
}
</script>
|