Skip to content Skip to sidebar Skip to footer

Custom Formatter In Jqgrid Which Calls Jquery Function

I have a jqGrid with a custom formatter that returns two checkboxes: jQuery(function($){ $('#gridAgenda').jqGrid({ ... colModel: [ ..., 'asiste',

Solution 1:

Finally I've solved this way:

gridComplete: function () {
        var rowData = $("#gridAgenda").getRowData();             
        for (var i = 0; i < rowData.length; i++) 
        {               
            var asisteSi="#asisteSi"+rowData[i].id;
            var asisteNo="#asisteNo"+rowData[i].id;             
            $(asisteSi).click(function(){           
                var actualSi = "#"+this.id;
                var actualNo = actualSi.replace("asisteSi","asisteNo");                 
                if($(actualSi).prop('checked')){
                    $(actualNo).prop('checked', false);                 
                }
                //TODO:llamada ajax
            });             
            $(asisteNo).click(function(){           
                var actualNo = "#"+this.id;
                var actualSi = actualNo.replace("asisteNo","asisteSi");
                if($(actualNo).prop('checked')){
                    $(actualSi).prop('checked', false);                     
                }
                //TODO:llamada ajax                 
            });
         }
}

The problem was that $(asisteSi) had the last value when do click, so I had to get the current Id

Solution 2:

You should put the callback attachment into the gridComplete option of the grid definition, just like this:

$('#gridAgenda').jqGrid({
    ...
    gridComplete: function () {
        $("#asisteSi").click(function () {
            // do your deed
        });
    }
});

Supplemental

By the way, if there are multiple rows in the grid, you should not use asisteSi as your id, because it won't be unique in the page, and that causes undefined behaviour.

Post a Comment for "Custom Formatter In Jqgrid Which Calls Jquery Function"