如何仅在选中或选中jqgrid复选框时触发事件

时间:2015-12-30 10:07:23

标签: jquery asp.net-mvc jqgrid asp.net-ajax

我为jqgrid实现了代码,在我的代码中选择每一行时,值的计数将显示在jquery数据表中。它正在计算值,即使我取消选中复选框,我尝试了很多方法来解决它,但没有用。请帮忙。我在这里附上代码供您查看。

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选择jqgrid行后,计数将显示在数据表Jquery datatable

1 个答案:

答案 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();
}

DEMO HERE