1
Vote

URL contains &undefined when sorting or refreshing a grid

description

Hi,

I have come into a situation where &undefined is appearing in the AJAX call to the server, which causes an Error 400.

The issue is with "renderRowsOnly" in gridmvc-ext.js

Please Refer to the following:
self.SetupGridHeaderEvents = function () {
                self.jqContainer.on('click', '.grid-header-title > a', function (e) {
                    self.gridSort = '';
                    e.preventDefault();
                    self.currentPage = 1;

                    if (self.gridFilterForm) {
                        var formButton = $("#" + self.gridFilterForm.attr('id') + " input[type=submit],button[type=submit]")[0];
                        var l = Ladda.create(formButton);
                        l.start();
                    }

                    // remove grid sort arrows
                    self.jqContainer.find(".grid-header-title").removeClass("sorted-asc");
                    self.jqContainer.find(".grid-header-title").removeClass("sorted-desc");

                    var mySearch = $(this).attr('href');
                    var isAscending = mySearch.indexOf("grid-dir=1") !== -1;
                    self.updateGrid(mySearch, function () {
                        if (l) {
                            l.stop();
                        }
                    });
You will notice that you are calling the function "updateGrid" as follows:
self.updateGrid(mySearch, function () {
                        if (l) {
                            l.stop();
                        }
                    });
whereas the definition for updateGrid is
 self.updateGrid = function (search, callback, renderRowsOnly)
You will notice you're not specifying the argument "renderRowsOnly", which is later used in the function "updateGrid", and finally causes the word "undefined" to appear in the URL, which, in certain cases, causes a Error 400 (when no other arguments exists)
var gridUrl = URI(self.loadDataAction + gridQuery + "&" + renderRowsOnly).normalizeSearch().toString();
I would suggest to either ensure that "renderRowsOnly" is initialized by all calling functions, or to add a conditional check
 if(renderRowsOnly)
                {
                    gridQuery += renderRowsOnly;
                }

  var gridUrl = URI(self.loadDataAction + gridQuery + "&").normalizeSearch().toString();

comments

psavva wrote Dec 26, 2014 at 3:40 PM

In Addition to the proposed change above, I have found that a simple Grid Refresh also comes up with the same issue, as gridQuery is empty when you try to refresh, and it still appends the & to the end of the URL.
I suggest the following fix.
    if (renderRowsOnly) {
                    gridQuery += renderRowsOnly;
                }

                if (gridQuery.length > 0)
                {
                    gridQuery += "&";
                }

                var gridUrl = URI(self.loadDataAction +gridQuery).normalizeSearch().toString();

wst wrote Apr 14, 2015 at 7:55 AM

has this already been fixed via NuGet?
I'm having also the problem. I try to filter a column and after clicking apply I get this:
Unhandled exception at line 61, column 13 in http://localhost:58033/Scripts/gridmvc-ext.js

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'updateGrid'
it crashes at this location:
            self.updateGrid(fullSearch, function () {
                if (l) {
                    l.stop();
                }
            });