Checkbox keep checked
I have that code from demos for field checkbox
{headerTemplate: function() {
var sss= $("<button>").attr("type", "button").text("Засел.")
.on("click", function () {
deleteSelectedItemsZaselenie();
});
sss.addClass("btn btn-success");
return sss;
},
itemTemplate: function(_, item) {
var checkbox1 = $("<input>").attr("type", "checkbox")
.prop("checked", $.inArray(item, selectedItemsZaselenie) > -1)
.on("change", function () {
$(this).is(":checked") ? selectItemZaselenie(item) : unselectItemZaselenie(item);
});
checkbox1.addClass("checkzoom");
checkbox1.attr("autocomplete","off");
return checkbox1;
},
But have a problem with chekcbox render, it still show like checked but in true it already unckecked. I noticed that if i sort code like a $("#jsGrid").jsGrid("sort", "sorterColor"); it help to see true state of checkbox, but it's not true decision
I'm not sure why you're using itemTemplate for this field, when there is already a predefined type: "checkbox".
What I have noticed is that the loaded data for a checkbox field must be null instead of '0' if the box is to be rendered as unchecked.
@flymikeG I'm addition have a code like below. It's all for sending message with checked rows, but after send ,checkbox still show like checked, but indeed it isnt, this bug disappear if i refresh page, or make a sort with grid and i dont now why. And i didn't understand what you mean by null and '0'.
var selectedItemsZaselenie = [];
var selectItemZaselenie = function(item) {
selectedItemsZaselenie.push(item);
};
var unselectItemZaselenie = function(item) {
selectedItemsZaselenie = $.grep(selectedItemsZaselenie, function(i) {
return i !== item;
});
};
var deleteSelectedItemsZaselenie = function() {
if(!selectedItemsZaselenie.length || !confirm("Вы уверены, что хотитет отправить письмо о заселении?"))
{ alert("Ничего не выбрано");
return;}
deleteClientsFromDbZaselenie(selectedItemsZaselenie);
selectedItemsZaselenie =[]
};
var deleteClientsFromDbZaselenie = function(deletingClients) {
var nashi = $.map(jsonTable, function(client) {
if ( ($.inArray(client, deletingClients) > -1))
{
return client;}
else
{
return null;
}
});
var jsonNashiSend = JSON.stringify(nashi);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.status >= 200 && xhr.status < 300) {
alert('Письмо отправлено');
} else
{
alert('Что-то пошло не так...');
}
}
}
xhr.open('POST', '/emailSendMass', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('emailSendStatus=1&myjson='+jsonNashiSend);
};
I'm not sure why you're using itemTemplate for this field, when there is already a predefined type: "checkbox".
What I have noticed is that the loaded data for a checkbox field must be null instead of '0' if the box is to be rendered as unchecked.
This NEEDS to be clear in the docs... I wasted some good time trying to get this to work...
Thanks! Cheers!