简体   繁体   English

如何使jQuery行不可编辑,并使用ajax调用将同一行保存在数据库中?

[英]How to make jquery row non editable and save the same row in Database using ajax call?

I made the inline edit true for jqGrid by using below code - 我使用以下代码对jqGrid进行了内联编辑:

 if (rowid) {
      if (rowid !== lastsel) {
          $("#prjectForecastData").jqGrid('restoreRow', lastsel);
          $("#prjectForecastData").jqGrid('editRow', rowid, true);
          lastsel = rowid;
       } else {
              $("#prjectForecastData").jqGrid('restoreRow', lastsel);
              lastsel = "";
          }
    }

But here in below code, while saving row, I want to make an ajax call in order to save that row in database. 但是在下面的代码中,在保存行的同时,我想进行ajax调用以将该行保存在数据库中。 and also want to make that row non editable. 并且还希望使该行不可编辑。 Right now 'clientArray' is used to save the value on browser temporarily.But unable to make it non editable after that. 现在, 'clientArray'用于临时保存浏览器中的值,但是之后无法使其不可编辑。

$("#saveForecastEditData").click(function(){
     $("#prjectForecastData").jqGrid('saveRow',lastsel, false, 'clientArray');
       jQuery('#prjectForecastData').editRow(lastsel,false);
});

So how to make an ajax call and make the row non editable after saving the row in DB successfully? 那么,如何在将行成功保存到DB中之后进行ajax调用并使该行不可编辑?

To make row non-editable you should add not-editable-row class to the corresponding row. 要使行不可编辑,应将not-editable-row类添加到相应的行。 The exact code can depend on jqGrid configuration which you use. 确切的代码可以取决于您使用的jqGrid配置。 For example you can just add the line 例如,您可以添加行

$("#" + lastsel).addClass("not-editable-row");

after the line with saveRow , but sorting or paging of local data will recreate the grid body and so it will remove any previously set classes or rows of the grid. 在带有saveRow的行saveRow ,但是对本地数据进行排序或分页将重新创建网格主体,因此它将删除任何先前设置的网格类或行。 To make the information persistent you can save it in local data together with the main data. 为了使信息的持久,您可以在本地保存data连同主数据。 For example you can do the following 例如,您可以执行以下操作

$("#saveForecastEditData").click(function () {
    var $myGrid = $("#prjectForecastData"), rowData;
    $myGrid.jqGrid("saveRow", lastsel, { url: "clientArray"});
    rowData = $myGrid.jqGrid("getLocalRow", lastsel);
    // add new property to the data
    rowData.modified = true;
    // add the "not-editable-row" immediately
    $("#" + lastsel).addClass("not-editable-row");
});

The code of "#prjectForecastData" grid can use rowattr : "#prjectForecastData"网格的代码可以使用rowattr

$("#prjectForecastData").jqGrid({
    // ... all your existing parameters here
    rowattr: function (rowData) {
        if (rowData.modified) {
            return {"class": "not-editable-row"};
        }
    }
});

It will restore the class "not-editable-row" on rows which was modified locally. 它将在本地"not-editable-row"上还原类"not-editable-row"

To get all modified rows and to send there to the server one can use the following code 要获取所有已修改的行并将其发送到服务器,可以使用以下代码

var data = $("#prjectForecastData").jqGrid("getGridParam", "data");
var modifiedData = $.grep(data, function (item) { return item.modified; } );
$.ajax({
    url: "someServerUtl",
    type: "POST",
    dataType: "json",
    data: {
        modifications: JSON.stringify(modifiedData)
    }
});

The exact parameters of $.ajax request will depend on your server code which get the data. $.ajax请求的确切参数将取决于获取数据的服务器代码。

In the way you will save all modified data using one ajax call. 这样,您将使用一个ajax调用保存所有修改的数据 Alternativaly you can just use another (server based) url in the call of saveRow . 另外,您可以在saveRow调用中使用另一个(基于服务器的) url In the case the data of one saved row will be automatically send to the server on in the format described in the documentation . 如果保存的一行数据将自动以文档中所述的格式发送到服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在JXTable中使空行可编辑 - How to Make empty row editable in JXTable 如何将已删除的行保存到数据库? - How to save the deleted row into database? 如何在Java中的GlazedLists / JTable中使列,行或单元格可编辑? - How to make a column, row or cell editable in a GlazedLists/JTable in java? JFace - 如何根据同一行中另一列的复选框值在 TreeViewer 中只编辑一列? - JFace - How can I make only one column editable in TreeViewer based on checkbox value from another column in the same row? 动态将不可编辑的JTable行设置为可编辑 - Dynamically set non-editable JTable row as editable 如何知道一行Jtable是否可编辑? - How to know if a row of Jtable is editable? 两个具有相同自定义模型的JXTables-如何使单元在一个表中可编辑但在第二个表中不可编辑? - Two JXTables with same custom model - How to make cells editable in one table but non-editable in the second? 单击按钮使整个行可编辑 - Make a whole Row editable on button click 使用ajax显示单击的行的详细信息以及从同一jsp中的数据库中获取的详细信息 - Displaying the details of a row clicked and details fetched from database in same jsp using ajax 另存为对象还是数据库中的一行? - Save as object or just a row in database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM