2015-08-03 48 views
-1

在jqgird中進行內聯編輯如何檢查是否選擇了任何行?在jqgird中進行內聯編輯如何檢查是否選擇了任何行?

我想顯示錯誤消息「請選擇一行!」當用戶點擊編輯而不選擇任何行時。這裏

@Oleg是代碼:

gridobject.jqGrid({ 
    url: getUrl, 
    datatype: 'json', 
    mtype: 'Get', 
    colNames: arryDisplayCol, 
    colModel: arryColSettings, 
    pager: jQuery(pPagerName), 
    rowNum: 20, 
    rowList: [20, 40, 80, 100], 
    height: '100%', 
    viewrecords: true, 
    loadonce: false, 
    grouping: false, 
    caption: caption, 
    emptyrecords: 'No records to display', 
    jsonReader: { 
     root: "rows", 
     page: "page", 
     total: "total", 
     records: "records", 
     repeatitems: false, 
     Id: "0", 
    }, 
    sortable: { 
     update: function (relativeColumnOrder) { 
      var grid = gridobject; 
      var currentColModel = grid.getGridParam('colModel'); 
      $.ajax({ 
       url: urls.Common.ArrangeGridOrder, 
       type: 'POST', 
       data: JSON.stringify(currentColModel), 
       contentType: 'application/json; charset=utf-8', 
       success: function (response) { 

       }, 
       error: function (xhr, status, error) { 
       } 
      }); 
     } 
    }, 
    autowidth: true, 
    shrinkToFit: true, 
    multiselect: IsCheckbox, 
    editData: myData, 
    sortname: arrColSettings[0].name, 
    editurl: urls.Admin.ProcessRequest, 
    serializeRowData: function (postdata) { 
     var tableNames = $("#grdData").getGridParam('caption').replace(' List', ''); 
     var columnNames = $("#grdData").getGridParam('colNames'); 
     var colNames = columnNames.toString(); 
     for (var i = 0; i < columnNames.length; i++) { 
      var colName; 
      if (columnNames[i] == "Id") { 
       colName = "Id" 
      } 
     } 
     if (!colName) { 
      colName = columnNames[1].toString(); 
     } 
     var sel_id = $("#grdData").getSelectedRowsIds(); 
     rowData = jQuery("#grdData").getRowData(sel_id); 

     var colValue = rowData[colName]; 
     return { x01: JSON.stringify(postdata), x02: tableNames, x03: colNames, x04: JSON.stringify(jsonType), x05: colName, x06: colValue }; 
    }, 
    reloadAfterSubmit: true, 

}).navGrid(pPagerName, { 
    edit: false, 
    add: false, 
    del: false, 
    search: false, 
    refresh: true, 
    refreshtext: "Refresh", 
    beforeRefresh: function() { 
     var tableName = $("#grdData").getGridParam('caption').replace(' List', ''); 
     ReloadGrid(tableName); 
    }, 
}); 

gridobject.jqGrid('inlineNav', pPagerName, 
       { 

        edit: true, 
        editicon: "ui-icon-pencil", 
        add: true, 
        addicon: "ui-icon-plus", 
        save: true, 
        saveicon: "ui-icon-disk", 
        cancel: true, 
        cancelicon: "ui-icon-cancel", 

        editParams: { 
         keys: false, 
         oneditfunc: null, 
         successfunc: function (val) { 
          if (val.responseText != "") { 
           var tableName = $("#grdData").getGridParam('caption').replace(' List', ''); 
           ReloadGrid(tableName); 
          } 
         }, 
         url: null, 
         aftersavefunc:null, 
         errorfunc: null, 
         afterrestorefunc: null, 
         restoreAfterError: true, 
         mtype: "POST", 
         alertcap: "Warning", 
         alerttext: "Please, select row" 
        }, 
        addParams: { 
         useDefValues: true, 
         addRowParams: { 
          keys: true, 
          extraparam: {}, 
          successfunc: function (val) { 
           if (val.responseText != "") { 
            var tableName = $("#grdData").getGridParam('caption').replace(' List', ''); 
            ReloadGrid(tableName); 
           } 
          } 
         } 
        } 


       } 
    ); 
+1

這是默認啓用。你嘗試過嗎? – Jai

+0

代碼在哪裏? – zed

+0

您應該發佈顯示您嘗試的代碼。有很多方法可以使用內聯編輯,例如''nlineNav','onSelectRow'內的'editRow'的調用,'formatter:「actions的使用''等等。您的問題只有在內聯編輯的相同*特定*使用情況下才有意義。所以你應該修改問題的文本幷包含更多細節。此外,您應該始終包含您使用的jqGrid的哪個版本*以及jqGrid的哪個分支(在版本<= 4.7中爲免費的jqGrid,Guriddo jqGrid JS或舊的jqGrid)。 – Oleg

回答

0

inlineNav自動檢測該行是否被選中與否。如果未選擇該行,則會顯示帶有文字「請選擇行」的消息。默認文本來自$.jgrid.nav.alerttext,在grid.locale-en.js文件或您使用的其他語言文件中定義。如果您的問題是要求修改默認文本「請選擇行」到「請選擇一行!」那麼您應該使用alerttext選項navGrid(選項應該定義在與refreshtext: "Refresh"相同的級別上)。

相關問題