How to select jqGrid row on checkbox click?

前端 未结 4 2028
醉酒成梦
醉酒成梦 2020-12-19 19:22

Below is my code for jqGrid, i\'d like to select row or highlight the current row, when i check a particular checkbox inside jqgrid row. right now onSelec

相关标签:
4条回答
  • 2020-12-19 19:35

    Put this at the and of your JS code in order to run selection when clicking a checkbox

    $("#list1").find('input[type=checkbox]').each(function() {
        $(this).change( function(){
            var colid = $(this).parents('tr:last').attr('id');
            if( $(this).is(':checked')) {
               $("#list1").jqGrid('setSelection', colid );
               $(this).prop('checked',true);
            }
            return true;
        });
    });
    

    example UPDATED AGAIN: http://jsfiddle.net/vCWNP/

    edit: this also should be done every time a new row is added. let me know if something else is to be fixed ;]

    0 讨论(0)
  • 2020-12-19 19:35

    It seems to me, that you could solve your problem very easy. What you try to do is already implemented in the jqGrid. If you remove the column name:'',index:'' which has empty name, which is NOT PERMITTED and include an additional jqGrid parameter multiselect:true all will work like you as need.

    0 讨论(0)
  • 2020-12-19 19:42

    One simple way to do that:

    jQuery(".jqgrow td input").each(function () {
        jQuery(this).click(function () {
            $("#grid").jqGrid('setSelection', $(this).parents('tr').attr('id'));
        });
    });
    
    0 讨论(0)
  • 2020-12-19 19:42

    on your onSelectRow function add:

    var flag = jQuery(this).find('#'+id+' input[type=checkbox]').prop('checked');
    if(flag){
          jQuery(this).css('background-color', 'red' )// row will be in red if checkbox is selected, you have to find out the current row here
    }
    
    0 讨论(0)
提交回复
热议问题