سؤال

In fact, I have 2 Qs: I'm usign jqgrid and I have a column with a custom checkbox formatter (say Passed), a cloumn named ID and some other columns.

Q 1) I want to set IDs to cells of Passed column and it should be the value of ID column cells. Any idea?

Q 2) How can I change the value of Passed column cells with jquery?

extra notes: 1) In fact, I'm using the MvcJqGrid in my MVC 4 project and I'm trying to handle change events of those checkboxes, to finally be able to get their values and send to related controller.

2) My Main problem is that I can't set correct or any values to those checkboxes or grid cells according to clicks on them.

For now, as a defeated try, my formatter is like this:

function pass(cellvalue, options, rowobject) {
    return '<input type="checkbox" id="' + cellvalue + '" checked="checked" onclick="chkChange(\'' + cellvalue + '\', \'#' + cellvalue + '\')" />';
}

for now, I push the ID cells values to the Passed cells and it works as expected. and the event func:

function chkChange(bval, id) {        
    if (bval != 'false')
        $(id).val('false');
    else
        $(id).val('true');        
}

By this code, I can't change the value of checkboxes. I think that maybe I should manipulate cell values instead of checkboxes. If so, it seems that the solution of this issue is the answer of my Q 2.

Thanks in advance.

هل كانت مفيدة؟

المحلول

Found it! Damn...! waisting 12 hours of my time...

I changed the formatter like this:

function pass(cellvalue, options, rowobject) {        
    return '<input type="checkbox" id="' + cellvalue + '" checked="checked" onclick="chkChange(\'#' + cellvalue + '\')" />';
}

and the event func like this:

function chkChange(id) {                
 if ($(id).val() != 'false')
    $(id).val('false');
 else
    $(id).val('true');       
}

and that damned bug goes away...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top