2012-11-07 21 views
0
$("#list").jqGrid({ 
    url: '/modulos/carga/cargaServiciosTarifa.ashx', 
    datatype: 'xml', 
    mtype: 'GET', 
    colNames: ['Precio Dia', 'Precio Hora','Unidad'], 
    colModel: [ 
       { name: 'preciodia', index: 'preciodia', width: 100, align: 'center', editable: true, sortable: false }, 
       { name: 'preciohora', index: 'preciohora', width: 400, align: 'center', editable: true, sortable: false }, 
       { name: 'Unidad', index: 'TSI_Unidad', width: 100, align: 'center',   editable: true, edittype: 'select', 
         editoptions: { value: "Dia:Dia;Hora:Hora" }, sortable: true } 
       ], 
autoencode: true, 
pager: '#pager', 
rowNum: 20, 
sortname: 'preciohora', 
sortorder: 'asc', 
sortable: true, 
autowidth: false, 
width: 733, 
height: -1, 
shrinkToFit: true, 
viewrecords: true, 
gridview: true, 
caption: 'Listado Servicios asociados a Tarifa', 
postData: {tarId: tarId.val()}, 
editurl: '/modulos/carga/cargaServiciosTarifa.ashx' 
}); 


//Paginador 
     jQuery("#list").jqGrid('navGrid', 
      '#pager', 
      { 
       alerttext: "Seleccione un precio.", 
       add: true, addtitle: "Crear precio", 
       del: true, deltitle: "Eliminar precio", 
       edit: true, edittitle: "Modificar precio", 
       search: false, searchtitle: "Búsqueda", 
       refresh: true, 
       cloneToTop: true 
      }, 
      { width: 360, resize: false, closeAfterEdit: true, recreateForm: true, viewPagerButtons: true }, 
      { width: 360, resize: false, closeAfterAdd: true, recreateForm: true, viewPagerButtons: true }, 
      { }, //Delete action 
      { closeAfterSearch: true, closeOnEscape: true } 
     ); 

有兩個文本框和一個選擇選項,我想知道如何禁用'Precio Dia'(第一個文本框)列,如果我選擇選項'Hora'select(第三列),另一種方式禁用'Precio Dia',如果我在選擇中選擇'Hora'!有沒有可能的方式來做到這一點,當我創建或編輯(沒有內聯編輯,我使用navGrid)?在Jqgrid中禁用輸入列

有沒有像HTML禁用的任何屬性可以添加到colModel定義?

謝謝。

回答

1

我認爲你可以在select元素上定義change處理程序。在處理程序內部,您可以根據select中當前選定的選項禁用或啓用第一個輸入字段。由於使用表單編輯,第一個輸入字段的ID將與第一列的名稱相同。另外,您需要在表單初始化期間執行相同的操作。相應的代碼將如下所示:

editoptions: { 
    value: "Dia:Dia;Hora:Hora", 
    dataInit : function (elem) { 
     setTimeout(function() { 
      $("#preciodia").prop("disabled", $(elem).val() === "Hora"); 
     }, 50); 
    }, 
    dataEvents: [ 
     { 
      type: 'change', 
      fn: function (e) { 
       $("#preciodia").prop("disabled", $(this).val() === "Hora"); 
      } 
     } 
    ] 
}, 
+0

嗨奧列格,我想我即將修復它,但螢火蟲告訴我,道具不是一個函數。你知道真的發生了什麼嗎?再次感謝。 – bombai

+0

@bombai:不客氣!看看[工作演示](http://www.ok-soft-gmbh.com/jqGrid/bombai.htm)並與您的代碼進行比較。您還應該在包含XML數據的服務器響應的HTTP標頭中驗證「Contain-Type」是「text/xml」。 – Oleg

+0

好的,我已經修復,是由jquery的版本,我的項目是1.4.3,並且道具不存在,我已經使用'$(#input).attr('disabled','disabled');只適用於jquery1.6或+!再次感謝! – bombai