1

I'm using free-jqGrid and jqGrid has the option to place selection checkboxes for you onto the grid. On my grid I have two columns in the beginning which is placed by jqGrid and not backed up by my own data: a record number column 'rn' and the checkbox for record selection 'cb' (multi select in my case).

I feature the jqGrid on a bootstrap website, so when the loadComplete event hits, I add 'from-control' class to a lot of edits, like the per column search boxes and basically every edit I can find on the page. (I also replace every ugly little icon to glyphicons. I manipulate the DOM of the toolbar buttons so they become real buttons, so they look nicer and chardin.js work well for example. And so on and on and on. The end result is much better than the original. BTW, I'm not sure if that's the best practice, I couldn't find a better way to make jqGrid more bootstrappy, but this can be another question).

When you apply form-control class to a checkbox, it bloats up. That's beneficial, because it's much easier to click on it, you don't need to have a magnifier glass (like for the original tiny checkbox). I can nicely resize the columns for all those data columns what I supply data for, but I cannot figure out how to widen the cb column so it can accommodate the bloated up checkbox.

  1. I tried adding a configuration for that column in my colModel:

Both

{
    name: 'cb',
    width: 38,
    align: 'center',
    sortable: false,
}

and

{
    width: 38,
    align: 'center',
    sortable: false,
}

failed, I got an error from jqGrid stating that the number of colModels doesn't match the number of supplied data. That's true, because the data behind the cb column is not backed up by me.

  1. I tried in the loadComplete

    var $ajaxGrid = $("#ajaxGrid");
    $ajaxGrid.jqGrid('setColProp', 'cb', { width: 38 });
    

That didn't give me an error, but also didn't change anything. Maybe I should put it into another event handler? Which?

  1. Then I tried to go down the rocky road of manipulation:

    $("#ajaxGrid_cb").css("width", "38px");
    $(".td_cbox").css("width", "38px");
    

As you see I separately widen the header and the td elements. But this causes the table horizontal scrollbar to appear. Yuck! I tried to tumble deeper into the hacking hole, and make a wider column on the grid narrower to make the scrollbar disappear, but this didn't help:

$("#ajaxGrid_Name").css("width", "435px");
$('td[aria-describedby="ajaxGrid_Name"]').css("width", "435px");

There must be a way. Now it's ugly. Screenshot:

enter image description here

(Another style problem you can also see is for the Combined column I specify align: 'center' in the colModel but it has no effect.)

Csaba Toth
  • 10,021
  • 5
  • 75
  • 121

1 Answers1

1

You can use multiselectWidth to specify the width of the multiselect column:

multiselectWidth: 38

One more alternative: you can change the columns width later using setColWidth which is the part of free jqGrid. I introduced the method originally in the answer as plugin to old jqGrid versions. Thus the following, for example, will work too:

onInitGrid: function () {
    $(this).jqGrid("setColWidth", "cb", 38);
}

The onInitGrid callback or jQuery event "jqGridInitGrid" are good place, where you can modify the grid before the data will be loaded.

P.S. I'm working now on including better support of Bootstrap in free jqGrid. Probably you will just need to use guiStyle: "bootstrap" in the next version of jqGrid to make jqGrid be "in Bootstrap style".

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Lots of good info and thanks for the great work. That particular project I use jqGrid with is not open source, but I can share in private some related code how I replace icons and customize for bootstrap. – Csaba Toth Feb 08 '16 at 08:01
  • @CsabaToth: You are welcome! [The demo](http://www.ok-soft-gmbh.com/jqGrid/OK/formEditOnDoubleClick-bootstrap1.htm) uses `guiStyle: "bootstrap", iconSet: "fontAwesome"` options and the latest sources from GitHub. Your feedback would be very interesting for me. – Oleg Feb 08 '16 at 09:40
  • Quick comments on the demo: size differences between the top and bottom toolbar: the buttons on the left of the toolbar are bigger on the bottom toolbar than the top. While the center pager section is the opposite: the top is a tiny bit bigger than the bottom. fa checkboxes are great, maybe the expand/collapse button (top right) could be font awesome too. I see the edit dialog has form-controls, my grid has in-place edit, I hope that in-place edit has also from-control inputs. Thanks! – Csaba Toth Feb 12 '16 at 03:12
  • @CsabaToth: You are welcome! If I understand you correctly, then you mean `vertical-align: bottom;` applied explicitly by bootstrap in the column headers instead of original `vertical-align: center;`. I don't like the CSS rule too. I think that I'll overwrite it. **About assigning `from-control` class to all multiselect checkboxes I'm not sure where you see the advantage. Could you explain this?** It's not difficult to add the class additionally to `cbox`, but it helps not if some important (for you) CSS rules will be overwritten. – Oleg Feb 12 '16 at 06:30