我为jqgrid实现了代码,在我的代码中选择每一行时,值的计数将显示在jquery数据表中。它正在计算值,即使我取消选中复选框,我尝试了很多方法来解决它,但没有用。请帮忙。我在这里附上代码供您查看。
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);
}
中
答案 0 :(得分:2)
您可以在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();
}