English 中文(简体)
jqGrid - Inline edit - Research dirty/ change cell
原标题:jqGrid - Inline edit - Detect dirty / changed cells

is there an example of using jqgrid s getChangedCells method to determine if data has changed?

I grepped getChangedCells in the downloadable demos for jqgrid, and could only find the function definition, not example usages of getChangedCells.

What I want to do is save the edits that a user s made if the user clicks on another row. But, I only want to submit the save if the row is dirty.

Thanks in advance, --Nate

问题回答

最后,我设法制定了一部法典,以发现我们想要的东西。

希望那里的任何支电网格(如Oleg)有足够的时间审查这一守则并改进。

示范守则将努力在网格中检测数据,并有一个名为的可编辑领域。 如果你想在更多的栏目中核对变化的数据,就必须加上与该栏相协调的“<代码>后”的变量。

为了在<代码>on SelectRow功能中获取先前的手机数据,我没有使用getCell方法,因为在文件中,红字显示:

Do not use this method when you editing the row or cell. This will return the cell content and not the actuall value of the input element

By disgrace I could check that the documentation was right :(. However the getCell function works properly with the current cell data.

这里是法典:

 // Declare variables used for inline edit functionality.
 var last_selected;
 var before_edit_value;
 var after_edit_value;
 $( #grid-id ).jqGrid({
...

onSelectRow: function(row_id){
    if(row_id && row_id !== last_selected) {
        /*
         * Determine if the value was changed, if not there is no need to save to server.
         */
         if (typeof(last_selected) !=  undefined ) {
            after_edit_value = $( #grid-id tr#  + last_selected +   .name_column input ).val();
         }

        if (before_edit_value != after_edit_value) {
            /*
             * Save row.
             */
            $( #grid-id ).jqGrid(
                 saveRow , 
                last_selected, 
                function(response){
                    /* SuccessFunction: Do something with the server response */

                    return true;    
                }, 
                 http://url.to.server-side.script.com/server-side-script.php , 
                {
                    additional_data:  example: additional string ,
                });
            }
            else {
                /*
                 * Restore the row.
                 */
                $( #grid-id ).jqGrid( restoreRow , last_selected);
            }

        before_edit_value   = $( #grid-id ).jqGrid( getCell , row_id,  name );
    }   

    last_selected       = row_id;

    /*
     * Edit row.
     */
    $( #grid-id ).jqGrid(
         editRow , 
        row_id, 
        true, 
        function() {/* OnEditFunction */}, 
        function(response) {
        /* SuccessFunction: Do something with the server response */

        return true;

    }, 
     http://url.to.server-side.script.com/server-side-script.php , 
    {
        additional_data:  example: additional string ,
    }); 
   },
...
});

在我的一个项目中,我做了以下工作:在编辑第一行之前,我记得全球变量中的浏览数据,在编辑之后,如果改变浏览数据,就只做检查。 与此类似(用双点击启动的老模式):

var beforeEditData;

function onGridDblClickRow(id) {
  if (isRowEditable(id)) {
    beforeEditData = grid.getRowData(id);
    grid.editRow(id, true, null, null,  clientArray , null, onRowAfterEdit);
    ...
  }
}
function onRowAfterEdit(row) {
  var data = grid.getRowData(row);
  if (!isDataChanged(beforeEditData, data)) {        
    return; // No changes
  }
  ... // Save data here
}
function isDataChanged(before, after){
  ... // Allows tricky logic for dirty data, e.g. one may trim spaces etc.
}

我这样做了。

In the View

<script type="text/javascript">

var $grid = $("#Grid");
var lastSelection;
var datachanged = false;

function gridInitialised() {
    var headers = $( th>div>:input );
    for (var h = 0; h < headers.length; headers[h++].onclick = (function () { if (datachanged) { $grid.saveRow(lastSelection); datachanged = false; } }));
}

function editRow(id) {
    if (id && id !== lastSelection) {
        if (datachanged) { $grid.saveRow(lastSelection); datachanged = false; }
        $grid.restoreRow(lastSelection);
        $grid.editRow(id, true);
        var inputs = $( # +id+ >td>:input[class="editable"] );
        for (var i = 0; i < inputs.length; inputs[i++].onchange = (function () { datachanged = true; }));
        lastSelection = id;
    }
}
</script>

@Html.Trirand().JQGrid(Model.Grid, "Grid")

第三部分

            Grid.ClientSideEvents.RowSelect = "editRow";
            Grid.ClientSideEvents.GridInitialized = "gridInitialised";

The gridInitialised code is to handle changes to the search filter.

纽约总部

正如Oleg几年前提到的那样,我使用了“光彩”功能,并将国旗作为<条码>extrapara<>。

比如,假定您的“模版”或一个隐藏的栏目

onSelectRow: function(id) {
                if (id && id !== lastgridsel) {
                    $("#myGrid").saveRow(lastgridsel, false, "clientArray", { IsDirty: "True" });
                    $("#myGrid").editRow(id, true, null, null, "clientArray");
                    lastgridsel = id;
                }
            },

接着,在“Save Point”点(就我而言,外部纽顿)上通过行道,内容大致如下:

$("#gridSaveBtn").on("click", function() {
            var batch = new Array();
            var dataIds = $("#myGrid").jqGrid("getDataIDs");
            for (var i = 0; i < dataIds.length; i++) {
                try {
                    $("#myGrid").jqGrid("saveRow", dataIds[i], false, "clientArray");
                    //get row data
                    var data = $("#myGrid").jqGrid("getRowData", dataIds[i]);
                    if (data["IsDirty"] === "True") {
                        batch.push(data);
                    }
                } catch (ex) {
                    alert(ex.Message);
                    $("#myGrid").jqGrid("restoreRow", dataIds[i]);
                }
            }
        });




相关问题
jqGrid - inline editing with autocomplete

I am sure that I saw it already in an example but can t find it again :( I have a jqGrid with inline editing. That works fine. One column has a select box with 200 entries. Those get retrieved from a ...

Powershell Hotkey to Erase Current Line?

I would like to execute a hotkey that would erase the current line in the powershell session. Is such a thing possible?

in-place edit in Rails 3

There are a few options for editing a model in-place while in the Show page, i.e. without having to load a form in the Edit page. For example, see http://www.ruby-toolbox.com/categories/...

Grid Inline editing with JavaScript, weird behaviour

I made this invoice page. There is a repeater that generates a table. There are invoice item descriptions coming into td tags encapsulated with div tags like this: <asp:Repeater ID="Repeater1" ...

Edit in place vs. separate edit page / modal?

I have some data that is broken up into sections, much like the Resume feature of StackOverflow Careers (it s not resume data, though), that is editable/create-able via a jQuery web app. It s a bit ...

jqGrid inline editing event on "Esc" cancel

Does anyone know if jqGrid inline editing throws events that can be handled? The following code is a simple example of what I m trying to accomplish: jQuery( #list ).jqGrid( editRow , 0, true, false,...

Can t jqeditable after appent an element for it

I wrote a script, to make a new element to my SQL db and my website. If the post is good, i will get back the ID of the post, so i can make a DIV box like the other DIVs. The problem is, I can inline ...