Hi,
I declared the below Kendo grid with checkbox column. Below is the javascript script
@model IEnumerable<NotificationTypesModel>
<script type="text/javascript">
function CloseNotificationPopup() {
$('#ManageNotifications').data('kendoWindow').close();
}
function OnNotificationsBound(e) {
e.preventDefault();
var grid = this;
var rows = grid.items();
$(rows).each(function (e) {
var row = this;
var dataItem = grid.dataItem(row);
if (dataItem.IsRowSelected == true) {
grid.select(row);
//dataItem.IsRowSelected = false;
}
});
}
function SaveNotificationPreferences() {
var items = [];
var notificationTypesGrid = $('#NotificationTypes').data("kendoGrid");
for (var i = 0; i < notificationTypesGrid.selectedKeyNames().length ; i++) {
var currentDataItem = notificationTypesGrid.selectedKeyNames()[i];
items.push(currentDataItem);
}
}
</script>
The below is the kendo grid
@(Html.Kendo().Grid(Model)
.Name("NotificationTypes")
.Columns(columns =>
{
columns.Select().Width(39).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:center", tabindex = "1" });
columns.Bound(p => p.NotificationTypeID).Visible(false);
columns.Bound(p => p.IsRowSelected).Visible(false);
columns.Bound(p => p.NotificationTypeName);
})
.Pageable(page =>
{
page.PageSizes(true);
page.PreviousNext(true);
page.Input(true);
page.PageSizes(new int[] { 5, 10, 20, 50, 100 });
})
.Sortable()
.PersistSelection()
.Events(e => e.DataBound("OnNotificationsBound"))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(false)
.PageSize(5)
.Model(model => model.Id(p => p.NotificationTypeID))
.ServerOperation(false)
)
)
Below is the class I am using to bind
public class NotificationTypesModel
{
public Guid NotificationTypeID { get; set; }
public string NotificationTypeCode { get; set; }
public string NotificationTypeName { get; set; }
public bool IsRowSelected { get; set; }
}
When the page loads I am selecting the rows based on the data retrieved from the database. This is done inside the OnNotificationsBound event.
And on the page there is a button which will save the selections back to the database. The issue I am having is in the SaveNotificationPreferences() method I am not getting the records of selections from all the pages. I am unable to figure out the issue.
I am using the below version of Kendo.
2017.3.1018.545