2016-04-11 14 views
2

düzenleme i checkbox .Ben verileri alıyorum kontrol hırsız olarak seçilen öğeleri görüntülemek için gereken süre bir jquery datatable ettiği ilk Kolon uygulaması .in checkboxes olduğunu var ajax response .Data binding çalışıyor, ancak checked özniteliği değil.Onay kutusu işaretlendi mülkiyet JQUERY Datatable sütunda çalışmıyor

custAct.success = function (status) { 
     try { 
       var response = JSON.parse(status); 
       activityCust.clear().draw(); 

    for (var i = 0; i < response.length - 1 ; i++) 
     { 
activityCust.row.add({ 0: '<input class="checkboxCust" checked=' + response[i].IsSelected + ' value="' + response[i].ID + '" data-id="' + response[i].ID + '" type="checkbox" />', 1: response[i].Name, 2: response[i].Hours }).draw();  
     } 

catch(ex) 
{ 
} 

Html kod:

burada
<table class="gridTableActivityCust hover"> 
          <thead> 
           <tr> 
            <th>Select</th> 
            <th>Activity Name</th> 
            <th>Hours</th> 
           </tr> 
          </thead> 
          <tbody> 
           @foreach (var item in Model.Activities) 
           { 
            <tr data-id="@item.ActId"> 
             <td> 
              <input class='checkboxCust' disabled="@item.Enabled" checked="@item.IsSelected" value="@item.ActId" data-id="@item.ActId" type='checkbox' /> 
             </td> 
             <td> 
              @item.ActivityName 
             </td> 
             <td> 
              @item.Hours 
             </td> 
            </tr> 
           } 
          </tbody> 
         </table> 

json yanıttır: 5 seçildiğinde sadece Etkinlik cevaben

[ 
    { 
    "ID": 1, 
    "Name": "Activity 1", 
    "Description": "nc", 
    "Hours": 2, 
    "Remove": false, 
    "Active": false, 
    "IsSelected": false, 
    "Disabled": true 
    }, 
    { 
    "ID": 2, 
    "Name": "Activity 2", 
    "Description": "lkn", 
    "Hours": 3, 
    "Remove": false, 
    "Active": true, 
    "IsSelected": false, 
    "Disabled": false 
    }, 
    { 
    "ID": 3, 
    "Name": "Activity 3", 
    "Description": "lkk", 
    "Hours": 2, 
    "Remove": false, 
    "Active": false, 
    "IsSelected": false, 
    "Disabled": true 
    }, 
    { 
    "ID": 4, 
    "Name": "Activity 4", 
    "Description": "kjhj", 
    "Hours": 3, 
    "Remove": false, 
    "Active": true, 
    "IsSelected": false, 
    "Disabled": false 
    }, 
    { 
    "ID": 5, 
    "Name": "Activity 5", 
    "Description": "mn", 
    "Hours": 7, 
    "Remove": false, 
    "Active": true, 
    "IsSelected": true, 
    "Disabled": false 
    }, 
    { 
    "ID": 6, 
    "Name": "Activity 6", 
    "Description": "kj", 
    "Hours": 5, 
    "Remove": false, 
    "Active": true, 
    "IsSelected": false, 
    "Disabled": false 
    }, 
    { 
    "ID": 7, 
    "Name": "Activity 7", 
    "Description": "hj", 
    "Hours": 8, 
    "Remove": false, 
    "Active": false, 
    "IsSelected": false, 
    "Disabled": true 
    }, 
    { 
    "ID": 8, 
    "Name": "gdfg", 
    "Description": "dgdfg", 
    "Hours": 4.4, 
    "Remove": false, 
    "Active": true, 
    "IsSelected": false, 
    "Disabled": false 
    } 
] 

burada benim kodudur. Ama kullanıcı arayüzünde tüm chec kboxlar seçiliyor.

Ekran Görüntüsü: Bu durumda

img

sadece Etkinlik 5 kontrol edilmelidir.

+0

Formu paylaşır mısınız. Sadece onay kutularının isimlerinin aynı olabileceğini varsayalım. –

+0

@AditShah Sorumu güncelledim. – VVN

+0

@AditShah onay kutularının adları aynıdır. – VVN

cevap

2

bu deneyin:

temelde JSON yanıtından HTML'nize checked=true veya checked=false yazıyor ne yapıyorsunuz
activityCust.row.add({ 0: '<input class="checkboxCust" ' + response[i].IsSelected? checked="checked":""+' value="' + response[i].ID + '" data-id="' + response[i].ID + '" type="checkbox" />', 1: response[i].Name, 2: response[i].Hours }).draw(); 

. İşaretli bir onay kutusu için geçerli HTML kodu checked="checked", işaretlenmemiş onay kutularının işaretli özniteliği hiç yoktur.

+0

Güzel ... iyi çalışıyor ... teşekkürler ... – VVN