What friends have the following problem, I am generating a dynamic table with jquery result of a query to a method of c # the method is
public JsonResult GetRequirentes(string term)
{
var Result = from c in db.MtoRequirentes
where c.Descripcion.ToString().Contains(term)
orderby c.Descripcion
select new Item
{
id = c.MtoRequirenteId.ToString(),
value = c.Descripcion.ToString()
};
return Json(Result.Take(10).ToList(), JsonRequestBehavior.AllowGet);
}
well to generate the table in html I use a function
function GetTableRequirentes(Id) {
if (Id > 0) {
$('#tblRequirentes').show();
$.ajax({
cache: false,
url: _urlBase + 'Requirentes/GetTableRequirentes',
type: "GET",
dataType: 'json',
data: { id: Id },
success: function (data) {
var resultado = $.parseJSON(JSON.stringify(data.data));
if (resultado.length > 0) {
console.log(resultado);
for (var i = resultado.length - 1; i >= 0; i--) {
var rows = "<tr>"
+ "<td class='text-center'><input type='checkbox' id='" + resultado[i].MtoRequirenteId + "'class='case'>" + "</td>"
+ "<td>" + resultado[i].Descripcion +"</td>"
+ "</tr>";
$('#tblRequirentes tbody').append(rows);
}
}
else {
$('#FileUpload1').show();
$('#Submit').show();
$('#Resultado').hide();
}
},
error: function (ex) {
alert('Error al Cargar la información relativa a requirentes.' + ex);
}
});
return false;
}
}
So here I have no problems, then I generate a function to be able to select all the checkboc in the table
$("#checkBoxAll").on("change", function () {
$(".case").prop("checked", this.checked);
});
this method selects all the checkboxes that exist in the table, now what I want is that when I remove the selection from a chexkbox (since not all are selected) I remove the selection from the checboc that marks all.
I'm trying it this way but it does not work.
$(".case").on("change", function () {
if ($(".case").length == $(".case:checked").length) {
$("#checkBoxAll").prop("checked", true);
} else {
$("#checkBoxAll").prop("checked", false);
}
});
They would be so kind as to give me a clue as to how I could solve this problem.
thanks