【问题标题】:How to add a formatter (date) to a jqgrid subgrid如何将格式化程序(日期)添加到 jqgrid 子网格
【发布时间】:2013-04-12 10:51:38
【问题描述】:

我遇到了一个问题,我有下一个jqgrid:

grid.jqGrid({
    datatype: "xml",
    url:'../Controladores/cPedidos.php?action=lpp',
    mtype: 'POST',
    colNames:['FECHA','PROVEEDOR','USUARIO'],
    colModel:[
        {name:'fecha_compra',index:'fecha_compra',width:120, sorttype: 'date',
            formatter: 'date', formatoptions: { srcformat: 'm/d/Y H:i', newformat: 'd/m/Y H.i'} },
        {name:'nombre',index:'nombre',editable: false, width:560},
        {name:'usuario_id',index:'usuario_id',width:100, editable: false}

    ],
    rowNum:100,
    rowList:[50,100,200],
    pager: '#paginacion',
    gridview:true,
    rownumbers:true,
    ignoreCase:true,
    sortname: 'fecha_compra',
    viewrecords: true,
    sortorder: "desc",
    caption:"Pedidos",
    height: "100%",
    subGrid : true,
    subGridUrl: '../Controladores/cPedidos.php?action=lac',
    subGridModel: [{ name  : ['Codigo','Cantidad','Articulo','Estado','Rubro','Observaciones','Fecha Recibido','Usuario'], 
        width : [50,50,450,60,60,150,0,0] }],
    ondblClickRow: function(id, ri, ci) {
        // edit the row and save it on press "enter" key
        grid.jqGrid('editRow',id,true,null,null, 'clientArray');
    },
    onSelectRow: function(id) {
        if (id && id !== lastSel) {
            // cancel editing of the previous selected row if it was in editing state.
            // jqGrid hold intern savedRow array inside of jqGrid object,
            // so it is safe to call restoreRow method with any id parameter
            // if jqGrid not in editing state
            if (typeof lastSel !== "undefined") {
                grid.jqGrid('restoreRow',lastSel);
            }
            lastSel = id;
        }
    }
}).jqGrid('navGrid','#pager',{add:false,edit:false},{},{},myDelOptions,{multipleSearch:true,overlay:false});

我正在将主网格上的日期格式化为 dd/mm//yy (FECHA),现在我需要对“fecha recibido”的子网格执行此操作,我不知道要放置格式化程序代码

你怎么能这样做?

【问题讨论】:

    标签: jquery jqgrid formatter subgrid


    【解决方案1】:

    您使用subGridModel 创建子网格。它仅使用有限的可能性来创建最简单的子网格(请参阅the documentation)。如果您需要在子网格中使用格式化程序,则需要使用更灵活的方式:Subgrid as Grid

    这种 subgid 的实现非常简单,非常灵活。您应该只在主网格中实现subGridRowExpanded 回调,而不是使用subGridModel。如果用户单击展开按钮 ("+") 以查看为您创建的子网格 jqGrid 在扩展行下的空行。如果创建空的<div> 元素,您可以在其中放置任何 信息,包括任何其他网格(子网格)。您需要做的只是创建具有一些独特id 属性的新<table> 元素,并将<table> 元素放置在jqGrid 之前为您创建的空<div> 元素内。通常,一个基于 <div> 的 id 构造表的 id,作为 subGridRowExpanded 回调的第一个参数。

    您可以在my old answer 中找到最简单的回调实现。另一个例子你可以找到here。您可以在 the documentation 中找到更多此类实现的示例,或者只是在 web 或 stackoverflow 上搜索 "subGridRowExpanded" 文本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      相关资源
      最近更新 更多