2011-07-12 36 views
0

我已經啓用了就地編輯的JQGrid。 數據庫字段 名字(必填項) 姓(非必需)我想檢查任何驗證劑量是否點燃,然後點擊按鈕

下面是場景:

網格編輯和刪除按鈕。
2.點擊編輯然後(編輯,刪除將被隱藏)和(保存,取消將被顯示)。
3.我已清除FirstName文本框中的值。
4.我按下提交按鈕,然後會顯示如下信息「名字:字段必填」 這是正確的
5.但我後面的按鈕(保存,取消將編輯替換,刪除這是錯誤

我想提出檢查點在以下功能

function inplaceSave(id) { 
     //Check point is required for Any Validation violation or unsuccessful save 
     jQuery('#list').saveRow(id); 
     //if it is success then following method should called else couldn't 
     changeActionState('save', id); 
    } 

以下是代碼:

jQuery(document).ready(function() { 
     //$.jgrid.defaults.loadtext = ''; 
     jQuery("#list").jqGrid({ 
      url: '@Url.Action("JQGridGetGridData", "TabMaster")', 
      datatype: 'json', 
      mtype: 'GET', 
      colNames: ['col ID', 'First Name', 'Last Name', ''], 
      colModel: [ 
         { name: 'colID', index: 'colID', width: 100, align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn']} }, 
         { name: 'FirstName', index: 'FirstName', width: 150, align: 'left', editable: true, editrules: { required: true, number: true, minValue: 40, maxValue: 100} }, 
         { name: 'LastName', index: 'LastName', width: 150, align: 'left', editable: true }, 
         { name: 'Edit', index: 'Edit', width: 70, align: 'center', editable: false, formatter: editFmatter, unformat: unformatEdit } 
        ], 
      pager: jQuery('#pager'), 
      hidegrid: false, 
      rowNum: 100, 
      rowList: [10, 50, 100, 150], 
      sortname: 'colID', 
      sortorder: "asc", 
      viewrecords: true, 
      multiselect: false, 
      //rownumbers: true, 
      imgpath: '@Url.Content("~/Scripts/themes/steel/images")', 
      caption: 'Tab Master Information', 
      editurl: '@Url.Action("JQGridEdit", "TabMaster")' 
     }).navGrid('#pager', { edit: false, add: false, del: false, search: false, refresh: false }); 
    }); 
function inplaceEdit(id) { 
     jQuery('#list').editRow(id); 
     changeActionState('edit', id); 
    } 
    function inplaceCancel(id) { 
     jQuery('#list').restoreRow(id); 
     changeActionState('cancel', id); 
    } 
    function inplaceSave(id) { 
     jQuery('#list').saveRow(id); 
     changeActionState('save', id); 
    } 
function changeActionState(action, id) { 
     if (action == 'edit') { 
      jQuery('#action_edit_' + id).css('display', 'none'); 
      jQuery('#action_delete_' + id).css('display', 'none'); 
      jQuery('#action_save_' + id).css('display', 'block'); 
      jQuery('#action_cancel_' + id).css('display', 'block'); 
     } 
     else { 
      jQuery('#action_edit_' + id).css('display', 'block'); 
      jQuery('#action_delete_' + id).css('display', 'block'); 
      jQuery('#action_save_' + id).css('display', 'none'); 
      jQuery('#action_cancel_' + id).css('display', 'none'); 
     } 
    } 

回答

0

我已經解決了這個問題,我自己,使用修改功能inplaceSave並增加了新的功能checkSave

這裏是更新的代碼。

function inplaceSave(id) { 
     jQuery('#list').saveRow(id, checkSave); 
    } 
    function checkSave(result) { 
     if (result.responseText.toLowerCase() == 'success') { 
      changeActionState('save', this.rowid); 
      refreshGrid(); 
     } 
    } 

謝謝
Imdadhusen

0

內聯編輯(未就地編輯)等editRow方法有更多的作爲一個參數。附加參數允許您在成功和不成功的數據驗證或數據保存的情況下執行不同的操作。

您使用的是哪個版本的jqGrid?爲什麼您繼續使用imgpath等參數?爲什麼你不使用formatter:'actions'?它似乎正是你所需要的。此外,您的代碼不清楚如何以及何時調用inplaceSave

此外,您作爲one of your previous question解決方案發布的editFmatter的代碼看起來不對。它可以用於從服務器發送並且未包含在問題文本中的Edit列的空間包含。 custom formatter具有單元通用文本作爲輸入。代碼function editFmatter(el, cellval, opts) {...;$(el).html(finalHTML)中的表達式$(el)沒有意義。自定義格式化程序的參數是(cellvalue, options, rowObject)。可能您想使用custom editing而不是自定義格式,但應該以其他方式使用:edittype:'custom', editoptions:{custom_element: editFmatter,...

相關問題