I have a checkbox in a cell to mark a state Yes or Not. I have the following code in column options.
var colsOption = [
{id: 'fondo_reserva' , header: "Fondo Reserva" , width :120, renderer : function(value, record, columnObj, grid, colNo, rowNo) {
var no= grid.getColumnValue('fondo_reserva', rowNo);
return "<input type=\"checkbox\" value=\"" + no + "\"" + (valor == "Si" ? " checked" : "") + " onclick=\"fondo_check(this)\" />";
}},
......
......
];
The function fondo_check became as follow:
function fondo_check(objeto) {
if( objeto.value == 'No' || objeto.value == 'null' ) {
objeto.value = "Si";
}
else {
objeto.value = "No";
}
};
The question is how can I update the field value? so when I save the data the value of the field it's updated.
Thanks
Continuing with the topic, I did a few modifications in the code such as:
In the function renderer the line of return now say
return "<input type=\"checkbox\" name=\"checkcajaFR_" + rowNo + "\" value=\"" + no + "\" " + (valor == "Si" ? " checked" : "") + " onclick=\"fondo_check(this)\" />";I added name attribute where checkcajaFR_1 contains the line number of the record (number 1) and function fondo_check stayed as:
fondo_check(objeto) {
// Here extracting the row number
var rowNO = parseInt(objeto.name.substring(objeto.name.search(/_/) + 1, objeto.name.length));
if( objeto.checked ) {
objeto.value = "Si";
mycuentasgrid.setColumnValue("fondo_reserva", rowNO, "Si");
}
else {
objeto.value = "No";
mycuentasgrid.setColumnValue("fondo_reserva", rowNO, "No");
}
};
This work fine only with existing records (I mean records loaded from backend database) but not on inserted records.
When I add a new record to grid, I click on the checkbox, I fill my others fields and I click on save icon, the data is saved in backend DB but field corresponding to checkbox is not updated staying with default value "No".
Somebody can tell me why this happens ?
Thanks in advance