First of all, I would recommend you use the latest version of the free jqGrid. 4.9.2. You can download it from GitHub or use the CDN directly (see here). Related URLs will be
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/css/ui.jqgrid.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.9.2/js/jquery.jqgrid.min.js"></script>
and optionally a language file
<script src="https://cdn.jsdelivr.net/free-jqgrid/4.9.2/js/i18n/grid.locale-de.js"></script>
The inclusion of the English language file grid.locale-en.js
not required since it is now included in the main code of the free jqGrid ( jquery.jqgrid.min.js
or jquery.jqgrid.src.js
).
Before I explain the problems in the old demo, I would recommend using the simplified $.jgrid.info_dialog
method to create a small dialog. The corresponding code may be
$grid.jqGrid("navButtonAdd", { caption: "Click me too!", onClickButton: function () { $.jgrid.info_dialog.call(this, "Warning",
The displayed dialog box will look below
If you want to use text elements from a locale file, then the code can be changed to the following
$grid.jqGrid("navButtonAdd", { caption: "Click me too!", onClickButton: function () { var $self = $(this), alertText = $self.jqGrid("getGridRes", "nav.alerttext"), alertTitle = $self.jqGrid("getGridRes", "nav.alertcap"), bClose = $self.jqGrid("getGridRes", "edit.bClose"); $.jgrid.info_dialog.call(this, alertTitle,
If you want to display exactly the same dialog box that displays free jqGrid, if no row is selected, the code can be especially simple
$grid.jqGrid("navButtonAdd", { caption: "Click me!", onClickButton: function () { this.modalAlert(); } });
In case you cannot customize the texts, but the use is really simple.
If you want to use createModal
and viewModal
, as in the old demo, you should understand the following. Due to many changes in the free jqGrid. The main compatibility issue in the code: you need to call $.jgrid.createModal
, setting this
to the grid DOM. Therefore, you need to change $.jgrid.createModal(...)
in the old demo to $.jgrid.createModal.call(this,...)
. The next problem in the old demo is very simple. The condition $("#"+alertIDs.themodal).html() === null
is incorrect in current versions of jQuery, and it is better to use $("#"+alertIDs.themodal).length === 0
. This is the next major issue in the old demo. The complete code may be, for example, the following
$grid.jqGrid("navButtonAdd", { caption: "Click me!", onClickButton: function () { var $self = $(this), p = $self.jqGrid("getGridParam"), gridId = p.id, alertIDs = { themodal: "myalertmod_" + gridId, modalhead: "myalerthd_" + gridId, modalcontent: "myalertcnt_" + gridId }, alertSelector = "#" + $.jgrid.jqID(alertIDs.themodal), alertText = $self.jqGrid("getGridRes", "nav.alerttext"), alertTitle = $self.jqGrid("getGridRes", "nav.alertcap"); if ($(alertSelector).length === 0) { $.jgrid.createModal.call(this, alertIDs, "<div>" + alertText + "</div>", { gbox: p.gBox, jqModal: true, drag: true, resize: true, caption: alertTitle, top: 100, left: 100, width: 200, height: "auto", closeOnEscape: true, zIndex: null }, "", "", true); } $.jgrid.viewModal( alertSelector, { gbox: p.gBox, toTop: true }); } });