Code below from other stackoverflow answer is used in jqGrid to implement checkbox using jquery UI in jqGrid top toolbar. This is used to toggle autoedit variable true – false states.
Checkbox caption is too wide for toolbar. How to change checkbox to toolbar button with two states which reflect autoedit true/false values (checked and unchecked states). Instead of check mark similar button should appear in pressed or checked state and in regular/unchecked state if clicked again.
Pure checkmark without caption cannot used since there should be some visual glue instead of checkbox rectangle if tolbar contains more than one such checkbox to distinguish them visually.
var autoedit=false;
$("#grid_toppager_left table.navtable tbody tr").append(
'<td><div><label><input class="ui-pg-div" tabindex="-1" type="checkbox" ' +
(autoedit ? 'checked ' : '') +
'id="AutoEdit" />Checbox caption which should appear as top toolbar button tooltip' +
'</label></div></td>');
$("#AutoEdit").change(function () {
if ($(this).is(':checked')) {
autoedit = true;
$("#AutoEdit").attr("checked", "checked");
} else {
autoedit = false;
$("#AutoEdit").removeAttr("checked");
}
});
I find your question very interesting. So I made some demos which shows how to implement “toggle” buttons in the navigator bar of jqGrid. In all demos I used top toolbar.
I decide to use jQuery UI Button widget. It allows different kind of buttons one from there, the “toggle” button we need. The buttons can be just a text, just an icon or be combination of the text and up to two icons (one icon before the text and another after the text). As the result one can create toolbars like the following:
or just icons only like
and
for the “checked” state.
Because I used the top toolbar I For the implementation I applied the path of some jqGrid CSS which I described here:
The code which add the custom button which you posted I would modified to
in case of pure text button with the text “Autoedit”. The corresponding additional CSS settings can be
In case of usage the icon with the text the code will be
To make the button with icon only without the text one need just add
text: falseoption in the list of.button({...})parametersIn both cases the following CSS can be used
For different demos you can find here:
To have the border over the button only on hovering you can change the CSS for the
.my-nav-checkbox > labeltoAs the result you will have (see the following demo):