2010-06-29 31 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'); 
    } 
}