2010-06-29 73 views
0

我正在使用JQGrid和json服務列出所有數據庫用戶的成員信息,因此網格的url指向我的json服務和方法。到目前爲止,一切正常,我可以添加和編輯用戶和修改數據,它可以很好地保存。然而,刪除數據庫用戶是另一回事,因爲Membership.DeleteUser將用戶名作爲其參數。在添加或編輯模式下,JQGrid似乎只能傳回可編輯的參數。但是,當你試圖刪除它時,似乎並不允許返回任何參數,我覺得這很奇怪。我剛剛開始使用JQGrid,所以我可能會變得很厚:-)。請誰能告訴我如何做到這一點?我有JQGrid自己的用戶名作爲列。我曾嘗試過各種事情日期:傳遞動態參數以刪除JQGrid中的url方法

網址: '雜項/ myservice.svc/AddEditDeleteGridRow用戶名=?' + $( '#MyGridTbl')getCell( 'selrow', '用戶名')在

。 navGrid的刪除部分。我也嘗試在選擇行事件中設置URL,但是我發現它需要重新加載才能將其插入到網格中,並且在發生這種情況時,所選行會丟失,從而導致對象失敗。我只需要能夠訪問/獲取json服務中的用戶名,以便將其傳遞給Membership.DeleteUser。我一直在尋找互聯網,似乎無法找到任何東西。

這是我使用的JQGrid。 json服務基本上只有GetData,它返回JQGridJSONData(json對象數據集)和AddEditDeleteGridRow方法,它們都是公共的。所有列數據都被髮送到json服務進行添加和編輯,但是沒有任何內容正在發送給刪除操作。

只是爲了澄清我需要在json服務的服務器端的用戶名。

$('#MyGrid').jqGrid({ 
    url: 'Misc/MyjsonService.svc/GetData', 
    editurl: 'Misc/MyjsonService.svc/AddEditDeleteGridRow', 
    datatype: 'json', 
    colNames: ['UserId', 'UserName', 'Email Address', 'Password Last Changed', 'Locked'], 
    colModel: [ 
       { name: 'UserId', index: 'UserId', hidden:true, editable: true, editrules:{edithidden: true}}, 
       { name: 'UserName', index: 'UserName', editable: true, width: 200, sortable: false, editrules: { required: true} }, 
       { name: 'Email Address', index: 'Email', editable: true, width: 500, sortable: false, editrules: { email: true, required: true} }, 
       { name: 'Password Last Changed', index: 'LastPasswordChangedDate', editable: false, width: 200, sortable: false, align: 'center' }, 
       { name: 'Locked', index: 'IsLockedOut', sortable: false, editable: true, edittype: "checkbox", formatter: 'checkbox', align: 'center' } 
      ], 
    rowNum: 20, 
    hidegrid: false, 
    rowList: [20, 40, 60], 
    pager: $('#MyGridPager'), 
    sortname: 'UserName', 
    viewrecords: true, 
    multiselect: false, 
    sortorder: 'asc', 
    height: '400', 
    caption: 'Database Users', 
    shrinkToFit: false, 
    onPaging: function(pgButton) { 
     this.DBUserId = null; 
    }, 
    onSelectRow: function(Id) { 
     if (Id && Id !== this.DBUserId) { 
      this.DBUserSelect(Id); 
     } 
    }, 
    loadComplete: function() { 
     if (this.DBUserId) 
      this.DBUserSelect(this.DBUserId, true); 
    }, 
    gridComplete: function() { 
     var grid = $('#MyGrid'); 
     var body = $('#AvailableDBUsersArea'); 
     if ((grid) && (body)) { 
      grid.setGridWidth(body.width() - 10); 

      //keep the grid at 100% width of it's parent container 
      body.bind('resize', function() { 
       var grid = $('#MyGrid'); 
       var body = $('#AvailableDBUsersArea'); 
       if ((grid) && (body)) { 
        grid.setGridWidth(body.width() - 2); 
       } 
      }); 
     } 
    } 
}).navGrid('#MyGridPager', 
     { add: true, edit: true, del: true, refresh: false, search: false }, //general options 
     { 
     //Options for the Edit Dialog 
     editCaption: 'Edit User', 
     height: 250, 
     width: 520, 
     modal: true, 
     closeAfterEdit: true, 
     beforeShowForm: function(frm) { $('#UserName').attr('readonly', 'readonly'); }, 
     beforeShowForm: function(frm) { $('#UserId').removeAttr('readonly'); }, 
     beforeShowForm: function(frm) { $('#UserId').attr('readonly', 'readonly'); } 
    }, 
     { 
      //Options for the Add Dialog 
      addCaption: 'Add User', 
      height: 250, 
      width: 520, 
      modal: true, 
      closeAfterAdd: true, 
      beforeShowForm: function(frm) { $('#UserName').removeAttr('readonly'); }, 
      beforeShowForm: function(frm) { $('#UserId').removeAttr('readonly'); }, 
      beforeShowForm: function(frm) { $('#UserId').attr('readonly', 'readonly'); } 
     }, 
     { 
      //Delete options 
      width: 350, 
      caption: 'Delete User', 
      msg: 'Are you sure you want to delete this User?\nThis action is irreversable.' 
     }, 
     {} //Search options 
    ); 
+0

不允許定義,比如'beforeShowForm'更多的作爲一個時間的函數。您應該更改「編輯」和「添加」對話框選項,使其只有「beforeShowForm」的一個定義。 – Oleg 2010-06-29 15:21:35

回答

2

有一些方法可以將其他參數添加到刪除URL。定義jqGrid,特別是colModel會有所幫助。

如果你有例如使用一個隱藏的列可以使用

hidden: true, editable: true, editrules: { edithidden: false }, hidedlg: true 

參數。然後在編輯對話框中將看不到隱藏的列,但列的值將被髮送。

另一種方式可以選擇,如果你需要修改URL發送刪除請求。您可以定義navGrid參數(見http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator#how_to_useprmDel paremeter),它可以像下面

{ onclickSubmit: function(rp_ge, postdata) { 
     rp_ge.url = 'misc/myservice.svc/AddEditDeleteGridRow?UserName=' + 
        $('#MyGridTbl').getCell (postdata, 'UserName'); 
    } 
}