2016-05-19 15 views
1

Ich möchte durch jede Zeile von Kendo-Gitter durchlaufen und das Kontrollkästchen von bestimmten Zeilen nur überprüfen. Hier ist, was ich bisher versucht habe.Aktivieren Sie das Kontrollkästchen in Kendo-Gitter

function LoadControllerGrid(list) { 

     $("#controllerGrid1").kendoGrid({ 
      data Source: { 
       type: "json", 
       // contentType: "application/json; charset=utf-8", 
       transport: { 
        read: { 
         url: "@Html.Raw(Url.Action("GetControllerList", "Account"))", 
         type: "POST", 
         dataType: "json" 
        }, 

       }, 
       schema: { 
        model: { 
         id: "Id", 
         fields: { 
          'Id': { type: "string" }, 
          'Name': { type: "string" }, 
          'Description': { type: "string" }, 
          'URL': { type: "string" }, 
         }, 

        }, 
        data: 'data', 
        total: 'TotalCount' 
       }, 
       complete: function (jqXHR, textStatus) { 
        //  HidePageLoader(); 

       }, 
       pageSize: 5, 
       serverPaging: true, 
       serverSorting: true, 
       serverFiltering: true, 
       columnMenu: true 
      }, 
      height: 300, 
      groupable: false, 
      sortable: true, 
      filterable: true, 
      pageable: { 
       refresh: true, 
       pageSizes: 5000 
      }, 
      columns: [{ template: '<input type="checkbox" id="#=Id#" class="gridCK" />', width: "35px" }, 
         { field: "Description", title: "Actions" }, ] 



     }); 

     var df = list; 
     var grid = $("#controllerGrid1").data("kendoGrid"); 
     grid.tbody.find("input").closest("tr").each(function (index, row) { 

      var dataItem = grid.dataItem(row); 
      for (var i = 0; i < df.length; i++) 
      { 

       if (df[i] == dataItem.Id) { 

        $("#controllerGrid1 tbody").find("tr[data-uid=" + dataItem.Id + "]").attr("checked"); 


     }); 


    } 

kann jemand erklären, was habe ich falsch gemacht ?? und schlagen Sie vor, ob es alternative Möglichkeiten gibt, dies zu tun. Vielen Dank im Voraus

Antwort

1

Ich habe eine Lösung gefunden.

var selected = $("#controllerGrid1 tbody").find("tr[data-uid=" + dataItem.uid + "]"); 
         selected 
         .find("td:first input") 
         .attr("checked", true); 

Es funktioniert für mich nach

statt nach oben Code hinzufügen
$("#controllerGrid1 tbody").find("tr[data-uid=" + dataItem.Id + "]").attr("checked"); 
+0

Vereinfachen Sie Ihre Auswahl: '$ ("# controllerGrid1 tbody tr [data-uid =" + dataItem.uid +„] td: erste Eingabe "). attr (" geprüft ", wahr);'. Keine Notwendigkeit, dass viele "finden" ... – DontVoteMeDown

Verwandte Themen