jqGrid colModel parameters inside php array

2019-02-20 06:56发布

问题:

I'm working with a project that uses jqGrid in the most recent version. The thing is that this project is PHP(5.6) and uses JSON to "translate/talk" to jqGrid framework, and colModel parameters are all inside PHP arrays. It works flawlessly but i'm unable to trigger dataInit of colModel "criacao" using the actual project's code. Thx for your time!

public function laudos($section)
    {
        $table = 'laudos';
        $fields = array('id','laudo','nome_fantasia','cliente','cadastro_id','email','senha','exame','descricao','criacao','exclusao','arquivo');
        $tabela = array(
            'colNames' => array('ID','Laudo','Clínica','Nome','Cadastro','Email','Senha','Exame','Descrição','Criação','Exclusão','Arquivo'),
            'colModel' => array(
                array('name'=>'id','hidden'=>true,'search'=>true,'key'=>true),
                array('name'=>'laudo','index'=>'laudo','width'=>70,'align'=>'center','search'=>true,'editable'=>true,'editrules'=>array('required'=>true),'sorttype'=>'integer','searchoptions'=>array('sopt'=>'[eq,cn]', 'clearSearch'=>false)),
                array('name'=>'nome_fantasia','search'=>true,'width'=>170,'align'=>'center','editable'=>false,'sorttype'=>'text','searchoptions'=>array('sopt'=>'[eq,cn]','clearSearch'=>false),'editrules'=>array('required'=>true)),
                array('name'=>'cliente','search'=>true,'width'=>170,'align'=>'center','editable'=>false,'sorttype'=>'text','searchoptions'=>array('sopt'=>'[eq,cn]','clearSearch'=>false),'editrules'=>array('required'=>true),),
                array('name'=>'cadastro_id','search'=>true,'hidden'=>true,
                    'editable'=>true,'edittype'=>'text','searchoptions'=>array('sopt'=>'[eq,cn]','clearSearch'=>false),'editrules'=>array('edithidden'=>true,'required'=>true),
                    'editoptions'=>array('dataInit'=>'[]')),
                array('name'=>'email','search'=>true,'hidden'=>true,'editable'=>true,'sorttype'=>'email','searchoptions'=>array('sopt'=>'[eq,cn]','clearSearch'=>false),'editrules'=>array('edithidden'=>true)),
                array('name'=>'senha','search'=>true,'hidden'=>true,'editable'=>true,'editrules'=>array('edithidden'=>true)),
                array('name'=>'exame','search'=>true,'width'=>50,'align'=>'center','editable'=>true,'sorttype'=>'text','searchoptions'=>array('sopt'=>'[eq,cn]','clearSearch'=>false),'formatter'=>'select','edittype'=>'select',
                    'editoptions'=>array('value'=>array('Biópsia'=>'Biópsia','Necrópsia'=>'Necrópsia','Citologia'=>'Citologia'))
                ),
                array('name'=>'descricao','search'=>true,'width'=>200,'align'=>'center','editable'=>true,'sorttype'=>'text','searchoptions'=>array('sopt'=>'[eq,cn]','clearSearch'=>false)),
                array('name'=>'criacao','search'=>true,'width'=>70,'formatter'=>'date','fixed'=>true,'resizable'=>false,'align'=>'center','sorttype'=>'date','searchoptions'=>array('sopt'=>'[eq,cn]','clearSearch'=>false), 'editoptions'=>array('dataInit'=>'function (elem) { $(elem).datepicker();')),
                array('name'=>'exclusao','search'=>true,'width'=>70,'formatter'=>'date','sorttype'=>'date','fixed'=>true,'resizable'=>false,'editable'=>true,'searchoptions'=>array('sopt'=>'[eq,cn]','clearSearch'=>false),'align'=>'center'),
                array('name'=>'arquivo','search'=>false,'width'=>60,'formatter'=>'arquivo','classes'=>'tabela_laudo_arquivo','editable'=>true,'searchoptions'=>array('sopt'=>false,'clearSearch'=>false))
            ),
            'sortname' => 'id',
            'caption' => 'Registros de Laudos Cadastrados',
            );

UPDATE: Using jQGrid $.extend, it was possible to set colModel attributes using php and a base java script with all jQGrid settings, properties and events.

EXAMPLE:

var p = $("#tabela-laudos").jqGrid("getGridParam");
        //=================================================
        p.colModel[p.iColByName.laudo] = $.extend(true,
            {},
            p.colModel[p.iColByName.laudo], //NEW VALUES BELOW
            {
                editoptions:
                {
                    placeholder: "Ex.: 17777"
                },
            }
        );

回答1:

Using jQGrid $.extend, it is possible to set colModel attributes settings, properties and events of colModel's even after inital settings loaded.

EXAMPLE:

var p = $("#tabela-laudos").jqGrid("getGridParam");
        //=================================================
        p.colModel[p.iColByName.laudo] = $.extend(true,
            {},
            p.colModel[p.iColByName.laudo], //NEW VALUES BELOW
            {
                editoptions:
                {
                    placeholder: "Ex.: 17777"
                },
            }
        );