【问题标题】:Jgrid Save cell on button clickJgrid在按钮单击时保存单元格
【发布时间】:2010-09-30 06:22:25
【问题描述】:

嗨, 我正在使用afterSaveCell,如果我们修改单元格就会触发,然后它就会触发。

我的场景是我在保存更改按钮时对数据库进行批量更新。但是当用户编辑单元格并到达另一个单元格时,我将修改记录在一个数组中。

但如果用户编辑单元格并单击“保存更改”按钮,单元格焦点不会丢失(仍处于编辑模式)并且afterSaveCell 不会被触发。

是否有任何方法可以在单击按钮时触发保存单元格,以便 afterSaveCell 触发。

请帮忙.. 谢谢..

【问题讨论】:

    标签: javascript jquery jquery-ui jquery-plugins jqgrid


    【解决方案1】:

    您可以调用saveCell 方法。此方法有iRowiCol 作为参数。要了解当前可编辑单元格的此参数,您可以将afterEditCell 添加到网格中。因此,您将 iRowiCol 的最后一个值保存在 jqGrid 外部的变量中,并在“保存更改”按钮的点击事件内部使用这些参数调用 saveCell

    【讨论】:

    • 好的..我会记住的..谢谢
    【解决方案2】:
    // This worked Perfectly fine for me, hope will work for you as well.
    var selectedCellId;
        var $gridTableObj = $('#jqGridTable');
        $gridTableObj.jqGrid({
            datatype : "jsonstring",
            datastr : gridJSON,
            height : ($(window).height() - 110),
            width : ($(window).width() - 80),
            gridview : true,
            loadonce : false,
            colNames : columnNames,
            colModel : columnModel,
            rowNum : gridJSON.length,
            viewrecords : true,
            subGrid : false,
            autoheight : true,
            autowidth : false,
            shrinkToFit : true,
            cellsubmit : 'clientArray',
            cellEdit : true,
            jsonReader : {
                root : "rows",
                repeatitems : false
            },
            onCellSelect : function(id, cellidx, cellvalue) { // use this event to capture edited cellID
                selectedCellId = cellidx; // save the cellId to a variable
            },
            loadComplete : function(data) {
                jQuery("tr.jqgrow:odd").addClass("oddRow");
                jQuery("tr.jqgrow:even").addClass("evenRow");
            }
        });
    

    // 附加点击事件 jqgrid "saveCell" 保存单元格。

    var gridCellWasClicked = false;
    window.parent.document.body.onclick = saveEditedCell; // attach to parent window if any
    document.body.onclick = saveEditedCell; // attach to current document.
    function saveEditedCell(evt) {
        var target = $(evt.target);
        var isCellClicked = $gridTableObj.find(target).length; // check if click is inside jqgrid
        if(gridCellWasClicked && !isCellClicked) // check if a valid click
            {
            var rowid = $gridTableObj.jqGrid('getGridParam', 'selrow');
        $gridTableObj.jqGrid("saveCell", rowid, selectedCellId);
        gridCellWasClicked = false;
        }
        if(isCellClicked){
            gridCellWasClicked = true; // flat to check if there is a cell been edited.
        }
    };
    

    【讨论】:

      猜你喜欢
      • 2017-01-05
      • 2016-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      • 2021-12-13
      • 1970-01-01
      相关资源
      最近更新 更多