jqGrid,gridReload未被触发

时间:2013-10-03 15:22:26

标签: jquery jqgrid triggers

这是我的网格的定义:

$grid = $("#schedule");

var last_selected_row;
$grid.jqGrid({
    url:'xtras/schedule.php',
    editurl:'xtras/schedule.php',
    datatype: "json",
    mtype:'GET',
    colModel:[
        {name:'Date',index:'Street_Date', sorttype:"date", formatter:'date', formatoptions: {newformat:'d M y'}, 
        searchoptions: {sopt: ['eq','ne','lt','le','gt','ge'] , dataInit: function (elem) { $(elem).datepicker({  dateFormat: "yy-mm-dd'"  }) } }, width:60},


        {name:'Master by',index:'master_by', width:60, sortable:false,
            formatter: function(cellvalue, options, rowObject){
                        if(cellvalue == '0000-00-00'){
                            var rel_date = rowObject[0];
                            var parse_d = $.datepicker.parseDate("yy-mm-dd",  rel_date);
                            parse_d.setMonth(parse_d.getMonth()-2);
                            var new_d = $.datepicker.formatDate( "d M y", parse_d); 
                        } else {
                            var parse_d = $.datepicker.parseDate("yy-mm-dd",  cellvalue);
                            var new_d = $.datepicker.formatDate( "d M y", parse_d); 
                        }
                        return new_d;
                    },
            formatoptions: {newformat:'d M y'}, 
            edittype: 'text',
            editable:true , 
            editoptions: {size:9, 
                dataInit: function(el) { 
                    setTimeout(function() { 
                        $(el).datepicker({ 
                            dateFormat: "d M y'" 
                        }); 
                    }, 200); 
                } 
            } 
        },

        {name:'MO',index:'MO', width:30, align:"center", sortable:false, formatter: "checkbox", editable:true, edittype:'checkbox', editoptions: { value:"Yes:No" }}

    ],
    height: "100%",
    minWidth: 900,
    rowNum:15,
    rowList:[10,15,20,30,50,100],
    viewrecords: true,
    sortname:"ID",
    sortorder: "desc",
    pager: '#schedule_pager',
    caption:"Release Schedule",

    loadonce:false,
    ajaxGridOptions: {cache: false},

    grouping:true,
    groupingView : {
        groupField : ['Date'],
        groupColumnShow : [true],
        groupOrder: ['desc'],
        groupDataSorted : true
    },

    gridview: true,

    ondblClickRow: function (row_id) {
        if(row_id != null) {
            if(row_id !== last_selected_row) {jQuery('#schedule').jqGrid('restoreRow',last_selected_row);
                jQuery('#schedule').jqGrid('saveRow',row_id);
                jQuery("#schedule").jqGrid('editRow',row_id, true);
                last_selected_row = row_id; 
            } else {
                last_selected_row=row_id;
            }
        } 
    }
});

之后:

$grid.jqGrid('bindKeys', {
    onEnter: function(rowid) {
        editingRowId = rowid;

        $grid.jqGrid('editRow',rowid,true,null, {}, null, {},function(){
            setTimeout(function(){
                $grid.focus();
                $grid.trigger("reloadGrid");
            },100);
        });
    }
});

所以$grid.trigger("reloadGrid");永远不会被触发....为什么会出现这种情况?以及如何解决它?

1 个答案:

答案 0 :(得分:0)

在回到这个问题之后,我以不同的方式解决了这个问题:

我没有使用永远不会触发的'bindKeys'(在我的代码中),而是在行编辑中使用了成功函数:

ondblClickRow: function (row_id) {
        if(row_id != null) {
            if(row_id !== last_selected_row) {
                jQuery('#schedule').jqGrid('restoreRow',last_selected_row);
                jQuery('#schedule').jqGrid('saveRow',row_id);
                jQuery("#schedule").jqGrid('editRow',row_id, true, null, 
                    function(){ $("#schedule").trigger("reloadGrid", [{current: true}]); }, 
                    'xtras/schedule.php', 
                    null,{},{},{}
                );
                last_selected_row = row_id; 
            } else {
                last_selected_row=row_id;
            }
        } 
    }

这完全重新加载网格