2015-10-16 37 views
0

我设法让按钮(名称:“SelectStores”)显示,但它处于默认模式下,并且与颜色和形状中的其余部分不匹配。如何更改这些属性?如何修改jqgrid表单中的按钮特征?

谢谢。

colModel:[{name: "PCROWID", width: 60, align: "center", editable:true, hidden:true, editoptions: {readonly:true}}, 
      {name: "PCST", width: 60, align: "center", editable:true, editoptions: {readonly:true}, editrules: {required:true, number:false}}, 
      {name: "PCLSEQ", width: 60, align: "center", editable:true, editoptions: {readonly:true}, editrules: {required:true, number:true}, formatter:'number', formatoptions:{decimalPlaces: 0, defaultValue: '0'}}, 
      {name: "PCACTIVE", width: 60, align: "center", editable:true, editrules: {edithidden:true}, edittype:"checkbox", editoptions: {value:"Y:N"}}, 
      {name: "SelectStores", width: 80, align: "center", editable:true, hidden:true, editrules: {edithidden:true}, edittype:"button", editoptions: {value:"Select Stores"}}, 

回答

0

该数据集是一个对象数组。因此,您可以通过数组中的索引访问每个对象,从第一个对象的0开始。

所以:

colModel[0] = { 
      name: "PCROWID", 
      width: 60, 
      align: "center", 
      editable: true, 
      hidden: true, 
      editoptions: { 
       readonly: true 
      } 

所以,你要访问的对象是在第4个指标,并可以在访问:

colModel[4] 

在那里,每个个人的财产可以被访问使用点符号:

colModel[4].name // this would return "Select Store" 
    colModel[4].align  // this would return "center" 
    colModel[4].editrules.edithidden // returns true 

所以,你也可以以同样的方式分配新值:

colModel[4].align = "left" 
colmodel[4].width = 60 

请记住,这只有在对象数组保持相同顺序时才有效。如果您将新项目添加到数组的开头,那么您尝试访问的项目将不再位于索引4处,并且突然您将编辑错误的项目。

所以,如果他们都是一样的,并应具有相同的属性,你可能要考虑做一些像一个循环,要么规范的所有对象的所有属性,或者找到你正在寻找一个:

for(var i = 0, length = colModel.length; i < length; i++){ 
    // set all widths to 60 
    colModel[i].width = 60; 

    // set only the "SelectStores" button alignment to "left" 
    if(colModel[i].name === "SelectStores"){ 
     colModel[i].align = "left"; 
    } 
} 

根据您的确切目的,有可能更有效的方法来做到这一点,但这将完成工作。

+0

谢谢你的详细答复。这有助于我理解jqgrid结构。我有一个后续问题。代码示例在哪里:(“colModel [4] .align =”left“”)你提供的是整体格式? –

0

我确实需要澄清我的问题。我试图修改的按钮不在网格中,而是在编辑窗体中。该列隐藏在网格中。

我确实找到了一个解决方案,那就是我的代码的编辑部分,我可以直接使用编辑表单。

这里是我的解决方案:

$('#SelectStores').click(function() { 
    ShowExtendedData(); 
}).addClass("fm-button ui-state-default ui-corner-all");