How to Disable CheckBox not select in webgrid

Posted by Madhav1406 under ASP.NET MVC on 3/15/2017 | Points: 10 | Views : 890 | Status : [Member] | Replies : 1
$(document).ready(function () {    

//2nd click event for header checkbox for select /deselect all
$(document).on("click", "#cbSelectAll", function () {
var ischecked = this.checked;
//alert(ischecked); // jQuery 1.7+
$('#checkableGrid').find("input:checkbox").each(function () {
this.checked = ischecked;
});
});

});


Grid code
columns:
grid.Columns(
grid.Column(format: @<text> <input type="checkbox" @(item.Conf_Is_Approved == true ? " disabled='disabled'" : null) value="@item.Conf_ID" name="ids" /> </text>, header: "{checkall}"),
grid.Column(columnName: "Conf_Name", header: "Assets Name", canSort: true, format: @<text>@Html.ActionLink((string)item.Conf_Name, "Index", new { id = item.Conf_ID.ToString() }) </text>),
grid.Column(columnName: "Conf_TypeName", header: "Type", canSort: true),
grid.Column(columnName: "Conf_Created_Date", header: "Created Date", canSort: true, format: (item) => string.Format("{0:d}", item.Conf_Created_Date)),
grid.Column(columnName: "Conf_Ser_Num", header: "Serial#", canSort: true),
grid.Column(columnName: "Conf_Tag_Num", header: "Tag#", canSort: true),
grid.Column(columnName: "Conf_Pur_Date", header: "Purchase Date", canSort: true, format: (item) => string.Format("{0:d}", item.Conf_Pur_Date)),
grid.Column(header: "Status", canSort: true, format: @<text> <span class="display-mode"> @(item.Conf_Is_Approved == true ? "Approved" : item.Conf_Is_Archive == true ? "Archive" : "Pending")</span> </text>)
)
)

<script>
$("#checkableGrid th").each(function () {
if ($.trim($(this).text().toString().toLowerCase()) === "{checkall}") {
$(this).text('');
$("<input />", { type: "checkbox", id: "cbSelectAll", value: "" }).appendTo($(this));
$(this).append("<span>&nbsp;&nbsp;All</span>");
}
});
//3rd click event for checkbox of each row
$("input[name='ids']").click(function () {
//alert('hi');
var totalRows = $("#checkableGrid td :checkbox").length;
var checked = $("#checkableGrid td :checkbox:checked").length;

if (checked == totalRows) {
$("#checkableGrid").find("input:checkbox").each(function () {
this.checked = true;
});

}
else {
$("#cbSelectAll").removeAttr("checked");
}
});
</script>





Responses

Posted by: Pandyamanav on: 11/24/2017 [Member] Starter | Points: 25

Up
0
Down
Hello

I think its is not suitable to check all the checkbox that either is checked or not

Simply single loop can do so much for you

Thanks

Madhav1406, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response