jQGrid Pager_left width too small with few columns

2019-07-15 11:08发布

问题:

I have a Model, View, and Controller that will automatically convert a DataTable to a jQGrid. It works as expected, unless the DataTable has only 2 columns. The data is rendered as expected, but the Pager_Left is forced to a width of 20px regardless of the screen or grid size.

I have tried to step through the code to find where this is happening, but cannot see anywhere I am making it happen.

When I am stepping through, it is after this line of code:

jQuery("#" + "@Model.GridId").jqGrid('navGrid', '#' + '@Model.PagerId', { edit: false, add: false, del: false, refresh: false }, {}, {}, {}, { multipleSearch: true, multipleGroup: false });

that the Pager_Left shrinks. If I comment out the code, it displays as expected, but then I don't get my custom buttons in the pager.

Exact same code with a wider table produces the expected results. I think jQGrid has some "feature" that tries to adjust the pager when there aren't many columns, but I don't know how to turn it off.

I can do this:

$('#' + '@Model.PagerId' + '_left').css('width', '');

right after the offending code and it display as expected, but I would rather not hack it with a jQuery call to remove the style after it is added.

How do I turn off the "feature", or override it using proper jQGrid settings?

回答1:

There are two places of jqGrid code where one makes some kind of "feature detection". See here (and especially the line‌​) and here). As the result width will be set in the case where it is not needed.

I find removing of width style of left pager the way without any side effect. So I find it good enough.