Karthik
Karthik

Reputation: 207

In kendo grid mulitiple checkbox selected geting only one value at jquery reading in mvc4

This is my kendo grid

 @(Html.Kendo().Grid(Model)
  .Name("grid1")
  .Columns(columns =>
  {
      columns.Bound(p => p.Associate).ClientTemplate("<input id='assetcheck' name='assetcheck' type='checkbox'  #= Associate == 'true' ? checked='checked':'' # class='chkbx'/>").Width(35).HeaderTemplate("<input id='checkall' type='checkbox' onclick='checkAll(this)'>").Filterable(false).Sortable(false); 
      // columns.Bound(p => p.IsAttached).ClientTemplate("<input type='checkbox' #= IsAttached == 'true' ? checked='checked' : '' #  onclick='attachedchanged(this);'  />");
      columns.Bound(p => p.AssetNumber).Title("Asset Number");// #= AssetId @<text></text>  ':'' #  onclick='attachedchanged(this);  == 'true'
      columns.Bound(p => p.AssetName);
      columns.Bound(p=>p.ParentAsset);
      columns.Bound(p => p.ParentCompany).Title("Company");
      columns.Bound(p => p.AssetId).Hidden();
  })
 //  .Pageable()
  .Sortable()
  .Scrollable(scr => scr.Height(400))
  .Filterable()
  .Selectable(s => s.Mode(GridSelectionMode.Multiple))
 // .Events(events => events.Change("Grid_OnRowSelectUID"))
//.Pageable(pageable => pageable
       // .Refresh(true)
       // .PageSizes(true)
      //  .ButtonCount(5))
         .DataSource
          (
          dataSource => dataSource
              .Ajax()
             // .PageSize(10)
              .ServerOperation(false)
              .Read(read => read.Action("GetAssociateAssetParent", "Asset").Data("getMsgType"))
                 //  .Model(model => model.Id(p => p.AssetId))
           )
    )

In save button click am calling

$('#btnsave').click(function (e){
var UsedBooks = "";
var grid = $("#grid1").data("kendoGrid");
grid.select().each(function () {
var dataItem = grid.dataItem($(this));
UsedBooks += dataItem.AssetId + ",";
});

}

In grid am selecting two checkboxs but here am getting second value ...first value am not getting to UsedBooks

Upvotes: 0

Views: 2728

Answers (1)

Ranga Reddy
Ranga Reddy

Reputation: 3066

  // getting kendo grid 
  var grid = $("#grid1").data("kendoGrid");

  // list of selected and unselected books
  var books = [];

  // getting all the checked rows
  grid.tbody.find("input:checked").closest("tr").each(function (index) {
    grid.select($(this));
    var dataItem = grid.dataItem($(this));
    dataItem.assetcheck = 'true';
    books.push(dataItem);
  });

  // getting all the unchecked rows
  grid.tbody.find("input:not(:checked)").closest("tr").each(function (index) {
    grid.select($(this));
    var dataItem = grid.dataItem($(this));
    dataItem.assetcheck  = 'false';
    books.push(dataItem);
  });

finally in ajax call send the whole data and save.

Upvotes: 1

Related Questions