I find your question very interesting. So I did a few demos that show how to implement the "toggle" buttons in the jqGrid navigation bar. In all demos, I used the top toolbar.
I decided to use the jQuery UI Button widget. It allows you to use different buttons from there, the "switch" button that we need. Buttons can be just text, just an icon or a combination of text and two icons (one icon before the text and the other after the text). As a result, you can create toolbars, for example:
and in the checked state
and in a βverifiedβ state
and in the checked state
or just icons, just like and for the checked state.
Because I used the top toolbar. For implementation, I applied the path to some jqGrid CSS, which I described here :
.ui-jqgrid .ui-jqgrid-toppager .ui-pg-div { padding: 1px 0; float: left; position: relative; } .ui-jqgrid .ui-jqgrid-toppager .ui-pg-button { height: 18px !important; cursor: pointer; } .ui-jqgrid .ui-jqgrid-toppager .ui-pg-div span.ui-icon { float: left; margin: 0 2px; }
The code that adds the custom button you posted will be changed to
var autoedit=false; ... $("#grid_toppager_left table.navtable tbody tr").append( '<td class="ui-pg-button ui-corner-all">' + '<div class="ui-pg-div my-nav-checkbox">' + '<input tabindex="-1" type="checkbox" id="AutoEdit" />' + '<label title="Checkx caption which should appear as button tooltip"' + ' for="AutoEdit">Autoedit</label></div></td>' ); $("#AutoEdit").button().click(function () { if ($(this).is(':checked')) { autoedit = true; alert("Autoedit mode is ON"); } else { autoedit = false; alert("Autoedit mode is OFF"); } });
in the case of a clean text button with the text "Auto-update". Appropriate advanced CSS settings may be
.ui-jqgrid .ui-pg-table .my-nav-checkbox { margin: 0px; padding: 0px; float: left; height: 18px } .ui-jqgrid .ui-pg-table .my-nav-checkbox > .ui-button > span.ui-button-text { margin: 0px; padding: 1px 2px 1px 2px; }
If you use an icon with text, the code will be
$("#AutoEdit").button({ icons: {primary: "ui-icon-mail-closed"} }).click(function () { var iconClass; if ($(this).is(':checked')) { autoedit = true; iconClass = "ui-icon-mail-open"; } else { autoedit = false; iconClass = "ui-icon-mail-closed"; } $(this).button("option", {icons: {primary: iconClass}}); });
To make a button with an icon only without text, you just need to add the text: false
option to the list of .button({...})
parameters
$("#AutoEdit").button({ text: false, icons: {primary: "ui-icon-mail-closed"} }).click(function () { ...
In both cases, you can use the following CSS
.ui-jqgrid .ui-pg-table .my-nav-checkbox { margin: 0px; padding: 0px; float: left; height: 18px } .ui-jqgrid .ui-pg-table .my-nav-checkbox > input { padding: 1px; } .ui-jqgrid .ui-pg-table .my-nav-checkbox > label { margin: 0px; } .ui-jqgrid .ui-pg-table .my-nav-checkbox > .ui-button > span.ui-button-text { margin: 0px; padding: 1px 2px 1px 16px; } .ui-button-icon-only { width: 16px; } .ui-jqgrid .ui-pg-table .my-nav-checkbox > .ui-button > span.ui-button-icon-primary { margin: -8px 0px 0px -8px; }
For different demos you can find here:
To have the border above the button only on hover, you can change the CSS for .my-nav-checkbox > label
to
.ui-jqgrid .ui-pg-table .my-nav-checkbox > label { margin: 0px; border-width: 0px; } .ui-jqgrid .ui-pg-table .my-nav-checkbox:hover > label { margin: 0px; border-width: 1px; }
As a result, you will have (see the following demo ):
- standard state button
- Hover buttons
- standard state "checked" button
- Bringing the state of the checked button