JQgrid复选框onclick更新数据库 [英] JQgrid checkbox onclick update database
问题描述
我的JqGrid中有一个复选框列,它是从数据库加载的,因此在加载时会被选中或未选中.
I have a checkbox column in my JqGrid which get loaded from DB, so it is either checked or not checked when it is loaded.
我想要的是:如果复选框被用户选中或取消选中,我想同时更新DB.我不希望用户按Enter或其他任何东西.只需单击一下即可将操作发送到数据库
What i want is : If checkbox is being checked or uncheked by user i want to update DB in at same. I dont want user to press enter or anything. only 1 click and send action to DB
名称:"Aktiv",索引:"Aktiv",宽度:100,编辑类型:"checkbox",对齐:"center",格式符:"checkbox",可true,formatoptions:{disabled:false} >
name: 'Aktiv', index: 'Aktiv', width: 100, edittype: 'checkbox', align: 'center',formatter: "checkbox", editable: true, formatoptions: {disabled : false}
推荐答案
您可以在loadComplete
内设置click
事件处理程序:
You can set a click
event handler inside of loadComplete
:
loadComplete: function () {
var iCol = getColumnIndexByName ($(this), 'Aktiv'), rows = this.rows, i,
c = rows.length;
for (i = 1; i < c; i += 1) {
$(rows[i].cells[iCol]).click(function (e) {
var id = $(e.target).closest('tr')[0].id,
isChecked = $(e.target).is(':checked');
alert('clicked on the checkbox in the row with id=' + id +
'\nNow the checkbox is ' +
(isChecked? 'checked': 'not checked'));
});
}
}
其中
var getColumnIndexByName = function(grid, columnName) {
var cm = grid.jqGrid('getGridParam', 'colModel'), i, l;
for (i = 1, l = cm.length; i < l; i += 1) {
if (cm[i].name === columnName) {
return i; // return the index
}
}
return -1;
};
您应该使用 jQuery.ajax 来代替alert
有关更新复选框状态的服务器.
Instead of the alert
you should use jQuery.ajax to send information to the server about updating the checkbox state.
您可以在此处观看演示.
这篇关于JQgrid复选框onclick更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!