チェックボックス付きMVCコントリブグリッド
-
28-09-2019 - |
質問
GirdViewのチェックボックス列をすべてチェックまたはチェックしていないサポートをヘッダーに追加する方法を探しています。
<table class="grid">
<th><input type="checkbox" name="chkall"/></th>
<th>Name</th>
<tr>
<td>
<input type="checkbox" id="chkItem_1"/>
</td>
<td>
Category 1
</td>
</tr>
<tr>
<td>
<input type="checkbox" id="chkItem_2"/>
</td>
<td>
Category 2
</td>
</tr>
</table>
解決
column.For(x => Html.CheckBox("mycheckbox", new { @class = "foo" }))
.DoNotEncode()
.Header("<th><input type=\"checkbox\" id="chkHeader" /></th>");
そして、jQueryを使用して、ヘッダーチェックボックスの変更イベントを処理し、他のすべてをチェック/チェックしてください。
$(function() {
$('#chkHeader').change(function() {
if ($(this).is(':checked')) {
$('.foo').attr('checked', 'checked');
} else {
$('.foo').removeAttr('checked');
}
});
});
他のヒント
以下は私のために働いています:
column.For(x => Html.CheckBox('chkBox', x.Published)).Named('Published');
所属していません StackOverflow