如何仅在选中或选中jqgrid的复选框时触发事件
How to trigger an event only when check box of jqgrid is selected or checked
我为 jqgrid 实现了代码,在我的代码中,选择每一行后,值的计数将显示在 jquery 数据 table 中。它正在计算值,即使当我取消选中我尝试了多种方法来解决它但没有用的复选框时。请help.I在此处附上代码供您查看。
Js脚本:-
function callme(fncount, lncount, i, gndr) {
var grid = $("#ListGrid");
var s;
s = jQuery("#ListGrid").jqGrid('getGridParam', 'selarrrow');
alert(s);
//if (s > 0) {
var yesrno = $("#ListGrid").find('input[type=checkbox]').is(':checked')
alert(yesrno);
if (yesrno == true) {
$.post('/TodoList/This_is_final', { 'FirstNameCount': fncount, 'LastNameCount': lncount, 'TotalSalary': i, 'GenderCount': gndr }, function (data) {
alert(JSON.stringify(data));
$('#example').dataTable({
"aaData": data,
"aoColumns": [{ "mData": "FirstNamecount" },
{ "mData": "LastNamecount" },
{ "mData": "Salary" },
{ "mData": "Gendercount" }],
retrieve: true,
"bDestroy": true,
paging: false,
}).fnDestroy();
});
}
}
控制器:-
public JsonResult This_is_final(int FirstNameCount, int LastNameCount, int TotalSalary, int GenderCount)
{
// Console.WriteLine(b);
List<Counting> lc = new List<Counting>();
Counting c = new Counting();
c.FirstNamecount = Convert.ToInt32(FirstNameCount);
c.LastNamecount = LastNameCount;
c.Salary = TotalSalary;
c.Gendercount = GenderCount;
//c.lc.Add(c);
//var data=c.lc.OrderBy(a => a.Salary);
lc.Add(c);
//// lc.ToList();
return Json(lc, JsonRequestBehavior.AllowGet);
}
upon selecting rows of jqgrid the count will be shown in a datatable
您可以在 jqgrid
onSelectRow
活动中进行,如下所示。希望对您有所帮助。
onSelectRow: function(row, isSelected) {
var rows = $("#ListGrid").jqGrid('getGridParam', 'selarrrow');
var totalRow = rows.length;
var totalAmount = 0;
$.each(rows, function() {
var rowData = $("#ListGrid").getRowData(this);
totalAmount += rowData["amount"] * 1;
});
dataTable.row($('#example').find('tbody tr')).remove().draw();
dataTable.row.add([totalRow, totalAmount]).draw();
}
DEMO HERE
我为 jqgrid 实现了代码,在我的代码中,选择每一行后,值的计数将显示在 jquery 数据 table 中。它正在计算值,即使当我取消选中我尝试了多种方法来解决它但没有用的复选框时。请help.I在此处附上代码供您查看。
Js脚本:-
function callme(fncount, lncount, i, gndr) {
var grid = $("#ListGrid");
var s;
s = jQuery("#ListGrid").jqGrid('getGridParam', 'selarrrow');
alert(s);
//if (s > 0) {
var yesrno = $("#ListGrid").find('input[type=checkbox]').is(':checked')
alert(yesrno);
if (yesrno == true) {
$.post('/TodoList/This_is_final', { 'FirstNameCount': fncount, 'LastNameCount': lncount, 'TotalSalary': i, 'GenderCount': gndr }, function (data) {
alert(JSON.stringify(data));
$('#example').dataTable({
"aaData": data,
"aoColumns": [{ "mData": "FirstNamecount" },
{ "mData": "LastNamecount" },
{ "mData": "Salary" },
{ "mData": "Gendercount" }],
retrieve: true,
"bDestroy": true,
paging: false,
}).fnDestroy();
});
}
}
控制器:-
public JsonResult This_is_final(int FirstNameCount, int LastNameCount, int TotalSalary, int GenderCount)
{
// Console.WriteLine(b);
List<Counting> lc = new List<Counting>();
Counting c = new Counting();
c.FirstNamecount = Convert.ToInt32(FirstNameCount);
c.LastNamecount = LastNameCount;
c.Salary = TotalSalary;
c.Gendercount = GenderCount;
//c.lc.Add(c);
//var data=c.lc.OrderBy(a => a.Salary);
lc.Add(c);
//// lc.ToList();
return Json(lc, JsonRequestBehavior.AllowGet);
}
您可以在 jqgrid
onSelectRow
活动中进行,如下所示。希望对您有所帮助。
onSelectRow: function(row, isSelected) {
var rows = $("#ListGrid").jqGrid('getGridParam', 'selarrrow');
var totalRow = rows.length;
var totalAmount = 0;
$.each(rows, function() {
var rowData = $("#ListGrid").getRowData(this);
totalAmount += rowData["amount"] * 1;
});
dataTable.row($('#example').find('tbody tr')).remove().draw();
dataTable.row.add([totalRow, totalAmount]).draw();
}