2017-03-08 94 views
0

我正在使用jqGrid將Json對象轉換爲常規HTML表格。從服務器我得到的對象,除了一件事情,一切都很好。我添加了一個實際上是複選框列的列。在每個複選框輸入的值屬性中,如果複選框被選中,我會將ID傳遞迴服務器。jqGrid隨機抽取複選框列

$("#membersGrid").jqGrid({ 
    url: '/Member/GetAllMembers', 
    mtype: "GET", 
    styleUI: 'Bootstrap', 
    datatype: "json", 
    colModel: [ 
     { label: 'Full Name', name: 'fullName', width: 150 }, 
     { 
      label: 'Select', editable: true, name: 'id', 
      edittype: 'checkbox', editoptions: { value: "true:false", defaultValue: "false" }, 
      formatter: "checkbox", formatoptions: { disabled: false }, width: 45 
     } 
    ], 
    viewrecords: true, 
    height: 250, 
    width: 640, 
    rowNum: -1, 
    ajaxSubgridOptions: { async: false }, 
}); 

當我定義真或假,並用默認值我想指出,假(未選中)爲每個默認值,並用每複選框產生的細胞值產生複選框列。

但相反我得到隨機託運的複選框:

enter image description here

當我在Chrome檢查元素,未經檢查的類型用這種方式自動生成:

<td role="gridcell" style="" title="" aria-describedby="membersGrid_id"> 
    <input type="checkbox" value="400" offval="no"> 
</td> 

,並檢查型像這樣:

<td role="gridcell" style="" title="" aria-describedby="membersGrid_id"> 
    <input type="checkbox" checked="checked" value="399" offval="no"> 
</td> 

有沒有其他方法可以告訴jqGrid避免使用defaultValue屬性檢查複選框?或者我做錯了什麼?

+0

看來你使用商業[Guriddo jqGrid JS](http://guriddo.net/?page_id=103334)。我無法幫助您,但我建議您嘗試使用[免費jqGrid](https://github.com/free-jqgrid/jqGrid)fork,這是我開發的。您需要將'styleUI:'Bootstrap''參數更改爲'guiStyle:「bootstrap」'(或'guiStyle:「bootstrapPrimary」')(請參閱[文章](https://free-jqgrid.github.io/getting -started/index.html#bootstrap))並修改用於將jqGrid文件加載到CDN URL的URL(請參閱[Wiki文章](https://github.com/free-jqgrid/jqGrid/wiki/Access- free-jqGrid-from-different-CDNs)) – Oleg

+0

如果免費的jqGrid 4.14.0中存在相同的問題,那麼我需要從服務器返回的測試JSON數據('/ Member/GetAllMembers')才能夠重現問題。 – Oleg

+0

@Oleg感謝您的回覆。我注意到一個有趣的事實。當我刪除名稱:基本上定義複選框的值屬性的'id'屬性時,所有複選框都未選中。當我將它歸還時,它會再次進行隨機檢查。我不確定如果複選框被選中,名稱屬性會如何影響... –

回答

1

我認爲存在關於formatter: "checkbox"的使用的誤解。它將輸入值truefalse顯示爲複選框的選中/未選中狀態。輸入數據的屬性id將用作rowid:行的id屬性的值(網格的<tr>元素)。

因此,我建議您更改name或將保留複選框的列。你的主要問題應該被修正。我建議你小心使用formatter: "checkbox", formatoptions: { disabled: false }。 jqGrid支持三種編輯模式:單元格編輯,內聯編輯和表單編輯,允許修改jqGrid的本地數據。此外,您目前不使用loadonce: true選項。因此根本不會創建本地數據:只有HTML表格中的數據將保存從服務器返回的信息。複選框formatter: "checkbox", formatoptions: { disabled: false }的更改將不會被跟蹤,您可能在讀取數據時遇到問題。全部取決於如何您讀取複選框的數據... The demo,我爲the answer創建,顯示如何修改本地 jqGrid的數據,以便保存複選框的狀態。