0

I am working in the Concrete5 CMS and I use the jquery jqGrid 4.5.4 version. I have problem while using the jqgrid in view form.

  1. First the label and data are collapsed
  2. Description is show long line, and I want to split in multiple lines based on the width (I want like this demo)
  3. How to set the width of the viewGridRow?

Some properties are not working in the jqGrid, like closeOnEscape, checkOnSubmit and checkOnUpdate

enter image description here

My code:

var grid = $("#projectGrid");
    var pages = <?php echo json_encode($pl) ?>;
    var emptyMsgDiv = $('<div>No Records.</div>');
    grid.jqGrid({
        caption:'Project List',
        datatype:'local',
        data:pages,
        mtype:'POST',
        colNames:['ID','Project Name','Assignment Name','Client','Start Dt.','Submission Dt.','Description'], 
        colModel:[ 
            {name:'proj_id', key:true, hidden:true}, 
            {name:'proj_name', width:200, sorttype:'text'}, 
            {name:'emp_name', width:200, edittype:'custom', editoptions:{custom_element:function(value, options) { return combobox_element(value, options,'emp_name') }, custom_value:combobox_value }},
            //{name:'c_company_name',width: 100},
            {name:'c_company_name', width: 100, align: "center", formatter: "select", editable: true,
                        edittype: "select", editoptions: {value: dataCli}},
            {name:'proj_start_dt', width:150, sorttype: 'date', formatter: 'date', formatoptions: { newformat: 'd-m-Y' }, 
                datefmt: 'd-m-Y', editoptions: { dataInit: initDateStart }, oneditfunc: function() {alert ("edited");},  
                searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'], dataInit: initDateSearch } },
            {name:'proj_end_dt',width:150, sorttype: 'date', formatter: 'date', formatoptions: { newformat: 'd-m-Y' }, 
                datefmt: 'd-m-Y', editoptions: { dataInit: initDateEnd }, 
                searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'], dataInit: initDateSearch } }, 
            {name:'proj_description', hidden:true, editrules:{edithidden:true}, edittype:'textarea', search: false  }],
        cmTemplate:{editable:true, editrules: {required:true}}, 
        emptyrecords: 'No records.',
        beforeRequest: function () {if (pages.length === 0) {grid[0].p.page = 0;}},  // fix the page number from 1 to 0 in case of no data  
        loadComplete: function () { var count = grid.getGridParam(); var ts = grid[0]; if (ts.p.reccount === 0) { grid.hide();  emptyMsgDiv.show(); } else { grid.show(); emptyMsgDiv.hide(); } },  
        width:777,      
        height:'auto',
        pager:'#projectPager',
        sortname: 'proj_id',
        sortorder:'asc',
        rowNum:10,
        rowList:[10,20,30],
        rownumbers:true,
        viewrecords:true,
        gridview:true,
        autoencode:true,
        loadonce:true,
        editurl:'<?php echo $this->action('deleteProject'); ?>',
        reloadAfterSubmit: true
        
    });
    
    grid.jqGrid('navGrid','#projectPager', {
            add:false, edit:true, view: true, del:true, search:true, refresh:true,
            editfunc: function(id){ window.location = 'editProject?pID=' + id;$("#div").html(id);}},    
            {jqModal: true, reloadAfterSubmit:false, closeOnEscape:true, closeAfterEdit: true},
            {jqModal: true, closeOnEscape: true, labelswidth: '100%', width: '600' },
            {jqModal: true, reloadAfterSubmit:false, closeOnEscape: true},
            {jqModal: true, closeAfterSearch: true, closeOnEscape: true, multipleSearch: true, overlay: true, recreateFilter: true }
        );
    emptyMsgDiv.insertAfter(grid.parent());
    //$("#projectGrid")[0].refreshIndex();
    $("#projectGrid").trigger("reloadGrid");

And one more request is Please review my code if any bad or wrong. suggest me how to do better than this. thank you for who help this.

Pablo Sarturi
  • 161
  • 1
  • 10
Kumar Shanmugam
  • 597
  • 1
  • 11
  • 40

1 Answers1

1

The options of the View are described in the documentation. It has no checkOnSubmit, checkOnUpdate options. The options exist in Add and Edit form, but not in View form. The default value of closeOnEscape is false. You should specify closeOnEscape: true if required.

It seems to me that to solve your main problem you need just set width and labelswidth options of View. You need add one more parameter of navGrid (after the options of Searching dialog).

UPDATED:

grid.jqGrid('navGrid', '#projectPager', {
    add:false, edit:true, view: true, del:true, search:true, refresh:true,
    editfunc: function(id){ window.location = 'editProject?pID=' + id;$("#div").html(id);}}, 
    // below are Edit options (prmEdit in the documentation)
    {jqModal: true, reloadAfterSubmit:false, closeOnEscape:true, closeAfterEdit: true},
    // below are Add options (prmAdd in the documentation)
    {jqModal: true, closeOnEscape: true},
    // below are Delete options (prmDel in the documentation)
    {jqModal: true, reloadAfterSubmit:false, closeOnEscape: true},
    // below are Search options (prmSearch in the documentation)
    {jqModal: true, closeAfterSearch: true, closeOnEscape: true, multipleSearch: true, overlay: true, recreateFilter: true},
    // below are View options (prmView in the documentation)
    {jqModal: true, closeOnEscape: true, labelswidth: '35%', width: 600}
);

UPDATED 2: The option closeOnEscape: true works only if the focus is set inside of View dialog. To make the code compatible with the current version of jQuery (to the current implementation of jQuery.focus()) one need set tabindex attribute on the "Close" button from the title of the View dialog. The View option could be used like below

{
    beforeShowForm: function ($form) {
        $form.find("td.DataTD").each(function () {
            var html = $(this).html().trim();  // &nbsp;<span>&nbsp;</span>
            if (html.substr(0, 6) === "&nbsp;" && html.trim().length > 6) {
                $(this).html(html.substr(6));
            }
        });
        $form.closest(".ui-jqdialog").find(".ui-jqdialog-titlebar-close").attr("tabindex", "-1");
    },
    recreateForm: true,
    closeOnEscape: true,
    labelswidth: '35%',
    width: 600
}

The demo demonstrates the above code.

UPDATED 3: By the way I posted the bug report to trirand and Tony already fixed the code of jqGrid from github (see here). So the next version of jqGrid will don't have the problem with closeOnEscape: true.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Sorry i can't understand the navGrid(after the options of Searching dialog). change the view and search order – Kumar Shanmugam Mar 19 '14 at 07:16
  • 1
    @KumarShanmugam: You confused Delete and View prameters of `navGrid`. See **UPDATED** part of my answer. – Oleg Mar 19 '14 at 07:24
  • Yeah i got but description value is scrolled (i want like this demo notes in warning row http://www.ok-soft-gmbh.com/jqGrid/WrappingInViewForm_.htm) and closeOnEscape is not working – Kumar Shanmugam Mar 19 '14 at 07:46
  • 1
    @KumarShanmugam: see the demo from **UPDATED 2** part of my answer. – Oleg Mar 19 '14 at 09:58
  • One small request will u see this post http://stackoverflow.com/q/22350114/2806972 I cant to find bug in this. – Kumar Shanmugam Mar 19 '14 at 10:16
  • @KumarShanmugam: The post don't have any code which could be debugged. If you provide the URL for the demo which uses `jquery.jqGrid.src.js` then I could post my comments. – Oleg Mar 19 '14 at 10:19
  • Ok i can understand I am using the jquery.jqgrid.min.js in my all jqgrid. – Kumar Shanmugam Mar 19 '14 at 10:23
  • @KumarShanmugam: I mean just that a picture can't be used to find **the origin** of the problem. One have to debug the problem. About the usage of `jquery.jqGrid.src.js` or `jquery.jqGrid.min.js`: one uses typically `jquery.jqGrid.src.js` during development and uses `jquery.jqGrid.min.js` in the final solution. One need at least temporary replace `jquery.jqGrid.min.js` to `jquery.jqGrid.src.js` to be able to debug jqGrid code. – Oleg Mar 19 '14 at 10:29
  • this origin is when I submit the editform have to {jqModal: true, viewPagerButtons: true, checkOnUpdate:true, savekey: [true,13], navkeys: [false,38,40], checkOnSubmit : true, reloadAfterSubmit:false, closeOnEscape:true, closeAfterEdit: true,width:600, height:300} the dialog box show empty (Not show any icon Yes, No, Cancel)... – Kumar Shanmugam Mar 19 '14 at 10:37
  • I try to use both jquery.jqGrid.min.js and jquery.jqGrid.src.js ... No use – Kumar Shanmugam Mar 19 '14 at 10:43
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/50015/discussion-between-kumar-shanmugam-and-oleg) – Kumar Shanmugam Mar 19 '14 at 10:44
  • Hi @Oleg If i want write this function(Updated2) like closeOnEscape in the jquery.jqgrid.min.js file. Where should I wrote this function. If you give the hint it very useful to me.. Thank you for all the comments and Your answer also. – Kumar Shanmugam Mar 19 '14 at 11:53
  • @KumarShanmugam: It's options of View options of `navGrid`. which you should use instead of `{jqModal: true, closeOnEscape: true, labelswidth: '35%', width: 600}` from the **UPDATE** part of my answer. – Oleg Mar 19 '14 at 12:19
  • Oh i am nee bee in the jqGrid I don't know this is the bug. Anyway the Delete options of 'navGrid' 'closeOnEscape: true' also not work, so fix t this also in the next version thank you. – Kumar Shanmugam Mar 19 '14 at 12:35
  • @KumarShanmugam: It's do a bug. I posted [the comment](https://github.com/tonytomov/jqGrid/commit/4a4f36924ec8ff8a37a6cb8b2478a4f994bc1290#commitcomment-5727575) and I hope that the code of Delete will be also fixed. – Oleg Mar 19 '14 at 13:16
  • @KumarShanmugam: Tony confirmed that it's a bug an have fixed it in the main code of jqGrid (see [here](https://github.com/tonytomov/jqGrid/commit/01ccd711cdcdf1870b07f763058e55085c985478)). Thank you for it! – Oleg Mar 21 '14 at 08:43
  • Hi @Oleg I got this error "$ is not defined" while i am using "jquery.jqGrid.src.js" or "jquery.jqGrid.min.js"... how to clear this error :) I am working in concrete cms, php and mvc pattern.. I got some int from this link http://stackoverflow.com/a/2195167 but i dnt know how to solve this – Kumar Shanmugam Apr 04 '14 at 13:10
  • @KumarShanmugam: the error "$ is not defined" means that you either don't included jQuery.js **before** `jquery.jqGrid.src.js` or `jquery.jqGrid.min.js` or if you included wrong or multiple versions of jQuery. – Oleg Apr 04 '14 at 13:50