views:

1074

answers:

4

I'm using a jqgrid to display the results of a search. When the search button is clicked it does this:

$("#Search").jqGrid('setGridParam', { url: url }).trigger("reloadGrid");

Where url contains the search params eg:

var url ="/search?first=joe&last=smith"

The web server is receiving this url and responding appropriately. But on the client side it throws this error in jqgrid.min.js line 21:

Syntax error:    
}); b.fn.jqGrid = function(f) { 

What can I do to fix this? I'm using jqgrid sucessfully in many other places, but this is the only one where I'm changing the url and reloading.

A: 

Try using the non minified version on this page to see more context of why it's surrounding. What you're seeing there is a where parsing is halting; I suspect your error is further up. This way you can see if the current url is being used and what's throwing it off.

Dan Heberden
Any idea where to download this from? I'm using 3.6.3. Dont want to update to 3.6.5 in case of new problems. The jqgrid documentation is useless. The blog posts announcing each new version don't even link to the download!
JK
Do you mean 3.5.3? http://www.trirand.com/blog/?page_id=6 - click the 3.5.3 link at the bottom; the zip is full of the uncompressed code.
Dan Heberden
The .min file has a comment saying "jqgrid 3.6.3". I am trying to rewrite the search in a different way to see if I can get past this error.
JK
Try adding a file extension to the url.. /search.php or whatever it is... does that fix it?
Dan Heberden
The url is fine, the server receives and responds to the request correctly. Its an MVC action, so it is a RESTful url.
JK
"Resolved" by changing it to not use the .trigger(reload) method..
JK
A: 

It seems to me that the error which you have in jqgrid.min.js corresponds an error in uncompressed version of jqGrid direct at the beginning of .jqGrid('setGridParam', { url: url }) (see line 82 of grid.base.js). It is the part of the so named "New API" introduced in 3.6 version of jqGrid. The code fragment started with following lines:

$.fn.jqGrid = function( pin ) {
    if (typeof pin == 'string') {
        var fn = $.fn.jqGrid[pin];
        if (!fn) {
            throw ("jqGrid - No such method: " + pin);
        }
        var args = $.makeArray(arguments).slice(1);
        return fn.apply(this,args);
    }
//...

I am not sure why you have a "syntax error", bu I recommend you to verify, that the id of the grid is really "Search". If you will don't find an error add more information in your question. For example: which version of jQuery you use? Including of a code fragment and the order of JavaScripts which you load would be also helpful.

Oleg
Yes its the right grid id. What do you mean by "an error uncompressed direct at the beginning of"? The server is receiving the url and parameters, so that means the url and the grid id are correct. Its the client side that has an error.
JK
I written you the only place in uncompressed version of jqGrid which corresponds the code `});b.fn.jqGrid=function(f){`. If the call of `jqGrid('setGridParam',..)` function work OK, than you posted in your question a wrong code fragment of jqGrid. Just use uncompressed version of jqGrid and you will see exact place of your problem.
Oleg
A: 

Instead of setting the url you should try something like this.

I am using this for custom drop downs that I add to the grid. Basicaly I conditionaly add 2 drop downs to the top toolbar section of the grid for quick searching.

var toolbarspan = $("<span>");

    if (tblDef.State != null) {
        $("<label>").attr("for", "selectState").append(" State: ").appendTo("#t_colch")
        $("<select>").attr("id", "selectState")
            .append($("<option>").attr({selected: true, value: "O"}).append("Open"))
            .append($("<option>").attr("value", "C").append("Closed"))
            .append($("<option>").attr("value", "B").append("Both"))
            .change(selChange)
            .appendTo("#t_colch")
       }

    $("<label>").attr("for", "selectInActive").append(" InActive: ").appendTo("#t_colch")
        $("<select>").attr("id", "selectInActive")
            .append($("<option>").attr({selected: true, value: "0"}).append("Active"))
            .append($("<option>").attr("value", "1").append("InActive"))
            .append($("<option>").attr("value", "B").append("Both"))
            .change(selChange)
            .appendTo("#t_colch");

    }

If you wanted your 2 fields in the top toolbar as well you will need to add the following to your table options.

 toolbar: [true, "top"],

First add this to your table definition.

beforeRequest: myBeforeRequest(this),

Then define your myBeforeRequest function something like this.

function myBeforeRequest(grid) {
    $(grid).jqGrid("setPostDataItem", "InActive", 0);
    var chkVal="";
    if ($("#selectInActive").length > 0)
    {
        chkVal = $("#selectInActive").val();
        if (chkVal == "B") $(grid).jqGrid("removePostDataItem", "InActive");
        else $(grid).jqGrid("setPostDataItem", "InActive", chkVal);
    }
    if (tblDef.State != null) {
        $(grid).jqGrid("setPostDataItem", "StateCol",  tblDef.State);
        $(grid).jqGrid("setPostDataItem", "State", "O");
        if($("#selectState").length > 0)
        {
            chkVal = $("#selectState").val();
            if (chkVal == "B") $(grid).jqGrid("removePostDataItem", "State");
            else $(grid).jqGrid("setPostDataItem", "State", chkVal);        
        }
    }
    }

You could do the same for your 2 searching fields even clearing them from the parameters if they are blank. This would result in the same url that you are manualy editing now. GetRecords.aspx?InActive=0&State=O&StateCol=9 is what I am currently getting at the server.

David
A: 

Refresh method works Ok for me. It is refreshing Dates (to and from) in each call.

The last two lines of code do all the magic.

I´m using it like this:

function refreshGrid() {    

    var gridSel = "#analyticsTbl";
    var fromDt = jQuery('#dpFrom').datepicker().val();
    var toDt = jQuery('#dpTo').val();

    var url = 'myService.asmx/MyWebMethod?fromdt=' + fromDt + '&' + 'todt=' + toDt;


    jQuery(gridSel).jqGrid({
        url: url,
        mtype: "GET",
        datatype: "xml",
        colNames: ['Product', 'Group', 'Score', 'Date'],
        colModel: [
                   { name: 'Product',  index: 'Product', sortable: true },
                   { name: 'Group', index: 'Group', sortable: true },
                   { name: 'Score', index: 'Score', sortable: true },
                   { name: 'Date', index: 'Date', sortable: true }
                  ],
        viewrecords: true,
        sortorder: "desc",
        caption: "Report",       
        hidegrid: false,
        autowidth: true,
        height: "100%"

    });

    jQuery(gridSel).jqGrid('navGrid', '#pgwidth', { edit: false, add: false, del: false });


    jQuery(gridSel).jqGrid('setGridParam', { url: url });
    jQuery(gridSel).trigger("reloadGrid");
}
Ro