"Undefined" message in jqgrid, "b.jgrid.formatter is undefined"
Asked Answered
P

1

15

when I'm sending JSON response to jqgrid I get "undefined" message across it and Firebug is telling me this:

b.jgrid.formatter is undefined

[Break On This Error]   

...input===true){b(".ui-pg-input",l).val(a.p.page);h=a.p.toppager?"#sp_1"+m+",#sp_1...

which basically doesn't tell me much.

This happens when I'm sending empty response:

{"total":0,"page":1,"records":0,"rows":[]}

or response with records. Records are then visible in grid. After this "undefined" message is shown up, I can't browse through pages as, of course, the bug in code appeared.

As @Oleg suggested I'm providing here additional info:

  1. These are javascripts I'm using:
    jquery.validate.min.js
    jquery.validate.unobtrusive.min.js
    jquery-1.5.1.min.js
    jquery-ui-1.8.11.min.js
    jquery.jqGrid.min.js
    ui/jquery.ui.core.js
    ui/jquery.ui.widget.js
    ui/jquery.ui.datepicker.js
  2. My javascript source:
    var grid = jQuery("#list").jqGrid({
                datatype: 'json',
    
                caption: 'Transaction Log',
                hiddengrid: 'true',
                postData: {
                    companyId: function () { return $("#SelectedCompany").val(); },
                    userId: function () { return $("#SelectedUser").val(); },
                    dateFromString: function () { return $("#DateFrom").val(); },
                    dateToString: function () { return $("#DateTo").val(); }
                },
                url: '@Url.Action("GetTransactionLogData")',
                mtype: 'GET',
                colNames: ['Ref.', 'TradeDate', 'Status', 'LegalEntity', ...],
                colModel: [
                    { name: 'Reference', index: 'Reference', width: '60' },
                    { name: 'TradeDate', index: 'TradeDate', width: '70' },
                    { name: 'Status', index: 'Status', width: '50' },
                    { name: 'LegalEntity', index: 'LegalEntity', width: '80' },
                    ...
                ],
                pager: $('#pager'),
                rowNum: 10,
                height: '100%'
    
            });
    
  3. I've downloaded last version of jqGrid from [this link][1], it's says it's **4.4.0** version.

How can I solve this?

Thanks in advance.

Periodical answered 29/6, 2012 at 9:5 Comment(2)
In case of such errors you should always 1) repeat the same with jquery.jqGrid.src.js instead of jquery.jqGrid.min.js 2) you should specify the exact version of jqGrid which you use 3) you should include the list of JavaScript files which you loaded on the page. The order of loading could be very important. 4) you should include the JavaScript code which defines jqGrid.Jarvisjary
Hi @Oleg, thank you for providing me with this list of details that I should present here in order to find solution with the community.Candiot
J
31

It's important to include grid.locale-en.js before jquery.jqGrid.min.js to make jqGrid working.

Additionally I would recommend you to add gridview: true option to jqGrid and replace pager: $('#pager') to pager: '#pager' because jqGrid need the id selector of the pager only. If you use pager: $('#pager') then jqGrid will replace the parameter to pager: '#pager'. So the form pager: $('#pager') has really no sense as the jqGrid parameter.

Jarvisjary answered 29/6, 2012 at 9:59 Comment(6)
@DevetiPutnik: $.jgrid.formatter will be defined in grid.locale-en.js and will be extended and used in jquery.jqGrid.src.js. So the text "b.jgrid.formatter is undefined" could be just because you didn't included grid.locale-en.js. Did you tried your code with jquery.jqGrid.src.js? Which error you get and in which line of jquery.jqGrid.src.js?Jarvisjary
Thank you very much! I rearranged the list a bit and now everything is working great!Candiot
Good catch @Jarvisjary . I added your solution to blog: blog.webdevilopers.net/… ThanksHaematosis
There's no JS error now, but I see "Warning Please, select row". This is when the returned list is emptyApparatus
@CsabaToth: Sorry, but I'm not sure that I understand you correctly. In any way the language file grid.locale-en.js or other grid.locale-XX.js should be included before jquery.jqGrid.min.js or jquery.jqGrid.src.jsJarvisjary
@Jarvisjary Yes, that solved the JS error and I marked your answer as correct! The other thing I refer to is a separate issue.Apparatus

© 2022 - 2024 — McMap. All rights reserved.