2016-04-11 16 views
2

で働いていない私が編集しているときに最初coloumnは、アプリケーション.IN checkboxesあるjquery datatableれてい確認thier checkboxは.Iからデータを取得していますをチェックして、私が選択した項目を表示する必要がありますajax response .Dataバインディングは正常に機能していますが、checked属性は正しくありません。ここチェックボックスは、プロパティはjQueryのDataTableの列

は私のコードです:

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コード:のみ活動5が選択されている応答で

[ 
    { 
    "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 
    } 
] 

<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応答です。しかしUIのすべてのchec kboxが選択されています。

スクリーンショット:この場合

img

のみ活動5をチェックする必要があります。

+0

フォームを共有できますか?チェックボックスの名前が同じであると仮定しているだけです。 –

+0

@AditShah私は私の質問を更新しました。 – VVN

+0

@AditShahチェックボックスの名前は同じです。 – VVN

答えて

2

これを試してみてください:

あなたは基本的にJSON応答から、あなたのHTMLに checked=trueまたは checked=falseを書いてやっている
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(); 

。有効なHTMLコードはチェックされたチェックボックスの場合はchecked="checked"です。チェックされていないチェックボックスにチェックされた属性はまったくありません。

+0

ニース...それはうまく動作しています。 – VVN

関連する問題