2011-07-22 31 views
7

jqGrid tham số loadonce: true được sử dụngLàm thế nào để xóa hàng với dữ liệu địa phương trong jqGrid

Lựa chọn hàng và nhấn nút delete

Không url được thiết lập

Làm thế nào để xóa các hàng trong dữ liệu địa phương chỉ và ngăn chặn thông báo lỗi này? Có thể đặt một số url giả hoặc bất kỳ ý tưởng nào khác để cho phép xóa hàng không? Sẽ tốt hơn nếu thêm và chỉnh sửa biểu mẫu cũng có thể được sử dụng với dữ liệu cục bộ.

  url: 'GetData', 
      datatype: "json", 
      multiselect: true, 
      multiboxonly: true, 
      scrollingRows : true, 
      autoencode: true, 
      loadonce: true, 
      prmNames: {id:"_rowid", oper: "_oper" }, 
      rowTotal: 999999999, 
      rownumbers: true, 
      rowNum: 999999999, 

Cập nhật 1

Từ Oleg trả lời tôi hiểu các giải pháp sau đây:

  1. chuẩn Disable jqGrid nút xóa
  2. Thêm nút xóa mới vào thanh công cụ.
  3. Từ nút này, nhấp vào gọi sự kiện được cung cấp

    grid.jqGrid ('delGridRow', rowid, myDelOptions);

. Nhiều hàng có thể được chọn. Làm thế nào để xóa tất cả các hàng đã chọn, mẫu này chỉ xóa một hàng?

Không nên thay đổi jqGrid sao cho xóa, chỉnh sửa, thêm nút hoạt động mà không có url? Hiện nay nó được yêu cầu để vượt qua url giả mà trở về thành công luôn luôn cho chỉnh sửa dữ liệu địa phương.

Trả lời

10

Bạn có thể sử dụng phương pháp delRowData để xóa bất kỳ hàng địa phương nào.

Bạn có thể sử dụng delGridRow từ chỉnh sửa biểu mẫu nếu bạn cần. Tôi đã mô tả cách thức here và được sử dụng cho trình định dạng: 'hành động' (xem here, here và ban đầu là here).

var grid = $("#list"), 
    myDelOptions = { 
     // because I use "local" data I don't want to send the changes 
     // to the server so I use "processing:true" setting and delete 
     // the row manually in onclickSubmit 
     onclickSubmit: function(options, rowid) { 
      var grid_id = $.jgrid.jqID(grid[0].id), 
       grid_p = grid[0].p, 
       newPage = grid_p.page; 

      // reset the value of processing option which could be modified 
      options.processing = true; 

      // delete the row 
      grid.delRowData(rowid); 
      $.jgrid.hideModal("#delmod"+grid_id, 
           {gb:"#gbox_"+grid_id, 
           jqm:options.jqModal,onClose:options.onClose}); 

      if (grid_p.lastpage > 1) {// on the multipage grid reload the grid 
       if (grid_p.reccount === 0 && newPage === grid_p.lastpage) { 
        // if after deliting there are no rows on the current page 
        // which is the last page of the grid 
        newPage--; // go to the previous page 
       } 
       // reload grid to make the row from the next page visable. 
       grid.trigger("reloadGrid", [{page:newPage}]); 
      } 

      return true; 
     }, 
     processing:true 
    }; 

và sau đó sử dụng

grid.jqGrid('delGridRow', rowid, myDelOptions); 

CẬP NHẬT: Trong trường hợp multiselect: true các myDelOptions thể được sửa đổi như sau:

var grid = $("#list"), 
    myDelOptions = { 
     // because I use "local" data I don't want to send the changes 
     // to the server so I use "processing:true" setting and delete 
     // the row manually in onclickSubmit 
     onclickSubmit: function(options) { 
      var grid_id = $.jgrid.jqID(grid[0].id), 
       grid_p = grid[0].p, 
       newPage = grid_p.page, 
       rowids = grid_p.multiselect? grid_p.selarrrow: [grid_p.selrow]; 

      // reset the value of processing option which could be modified 
      options.processing = true; 

      // delete the row 
      $.each(rowids,function(){ 
       grid.delRowData(this); 
      }); 
      $.jgrid.hideModal("#delmod"+grid_id, 
           {gb:"#gbox_"+grid_id, 
           jqm:options.jqModal,onClose:options.onClose}); 

      if (grid_p.lastpage > 1) {// on the multipage grid reload the grid 
       if (grid_p.reccount === 0 && newPage === grid_p.lastpage) { 
        // if after deliting there are no rows on the current page 
        // which is the last page of the grid 
        newPage--; // go to the previous page 
       } 
       // reload grid to make the row from the next page visable. 
       grid.trigger("reloadGrid", [{page:newPage}]); 
      } 

      return true; 
     }, 
     processing:true 
    }; 

CẬP NHẬT 2: Để có hỗ trợ bàn phím trên thao tác Xóa và đặt nút "Xóa" là defaul bạn có thể thêm vào tùy chọn bổ sung delSettings

afterShowForm: function($form) { 
    var form = $form.parent()[0]; 
    // Delete button: "#dData", Cancel button: "#eData" 
    $("#dData",form).attr("tabindex","1000"); 
    $("#eData",form).attr("tabindex","1001"); 
    setTimeout(function() { 
     $("#dData",form).focus(); // set the focus on "Delete" button 
    },50); 
} 
+0

cảm ơn. Tôi đã cập nhật câu hỏi dựa trên câu trả lời của bạn – Andrus

+1

@Andrus: Nếu bạn sử dụng thanh điều hướng của jqGrid bạn chỉ có thể sử dụng 'myDelOptions' làm tham số' prmDel' của [navGrid] (http://www.trirand.com/jqgridwiki/doku) .php? id = wiki: định nghĩa # navigator). Tôi đã đăng mã cách thực hiện chỉnh sửa biểu mẫu cục bộ và đăng [đề xuất tương ứng] (http://www.trirand.com/blog/?page_id=393/bugs/small-bug-in-generating-new-id-in -postit-of-editgridrow/# p22393) đến diễn đàn trirand.Tôi không thể làm được nữa. Tiếp theo bạn đã viết về cách sử dụng 'multiselect: true' ngay bây giờ. Đó là ** yêu cầu hoàn toàn mới **. jqGrid không định hướng của mustiselect trong chỉnh sửa lưới. – Oleg

+0

cảm ơn bạn. Các tùy chọn được đăng trong các câu hỏi ban đầu có 'multiselect: true'. Nút xóa tiêu chuẩn jQgrid xóa tất cả các hàng đã chọn nhưng cung cấp thay thế cục bộ sẽ chỉ xóa một hàng. – Andrus

Các vấn đề liên quan