Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqgrid checkbox change event

I have true/false values in my database. I want to update them with checkbox in jqgrid. Once the value is set to true, it will remain true and should not change. Please take a look at my column model :

{
    name : 'available',
    width : 12,
    resizable: true,
    editable: true,
    align: 'center',
    edittype:'checkbox',
    formatter: "checkbox", formatoptions: {disabled : false},
    classes:'check',
    editrules:{required:false}, editoptions:{size:39,value:"True:False"}
}

I'm trying to capture the event when checkbox is checked, currently they are all unchecked, so far I've tried:

jq(".check input").each(function(){
    jq(this).click(function(){
        aler("works");
    });
});

jq("input[type='checkbox']").change(function(){
    alert("works");
}); 

jq(":checkbox").parent().click(function(evt) {
    if (evt.target.type !== 'checkbox') {
        var $checkbox = jq(":checkbox", this);
        $checkbox.attr('checked', !$checkbox.attr('checked'));
        $checkbox.change();
        alert("");
    }
});

None of these work, I'm stuck don't know what else to try.

When inspect checkbox code with firebug it looks like this :

<input type="checkbox" offval="no" value="false">
like image 778
London Avatar asked May 22 '11 21:05

London


1 Answers

You can create a custom formatter. In your grid,

formatter: cboxFormatter,

Then define the function,

function cboxFormatter(cellvalue, options, rowObject)
{
  return '<input type="checkbox"' + (cellvalue ? ' checked="checked"' : '') + 
      'onclick="alert(' + options.rowId + ')"/>';
}

You can use onclick to perform your task or call a function.

like image 81
hyperslug Avatar answered Sep 27 '22 20:09

hyperslug