Skip to content

Commit

Permalink
new idMode of filterToolbar
Browse files Browse the repository at this point in the history
!!! BREAKING  CHANGES !!!

The changes fixs the problem of id duplicates in the filter toolbar if
more as one grid with the filter toolbar exist on the same page and the
grids have *the same column names* in multiple grids.

The new option `idMode` allows to manages the way of id generation.
- The default value `idMode: "new"` creates safe ids based on the rule:
`"gs_" + gridId + columnName`.
- The option `idMode: "compatibility"` creates the ids based on another
rule: `"gs_" + idPrefix + columnName`. The rule would be helpful only if
one uses `idPrefix` options with *different* `idPrefix` values for every
grid. One can still have id duplicates if one don't use any `idPrefix`
option.
- The option `idMode: "old"` forces the usage of old rule for building
of the ids of the filter elements: `"gs_" + columnName`.

It's important to mention, that the current changes are important **only
if one uses some rule for input field directly in your code**. It's
recommended that you scan your code for the string `gs_` to be sure,
wthere you should make any changes in your code at all. If you will find
the places in your then you can either adjust the place of the code or
to use `idMode` with the value `"compatibility"` or `"old"` to revert
the rule of id building to the old one.

If you would like to change the default value of `idMode` option
globally to the value `idMode: "compatibility"` for example, you can
include the following code *before* call of `filterToolbar` method (for
example directly at the beginning of you code):
```JavaScript
$.jgrid = $.jgrid || {};
$.jgrid.search = $.jgrid.search || {};
$.jgrid.search.idMode = "compatibility"; // or "old" instead of default
"new", which creates safe id values
```
  • Loading branch information
OlegKi committed Mar 8, 2016
1 parent b3c04ad commit 7cc6120
Show file tree
Hide file tree
Showing 9 changed files with 432 additions and 406 deletions.
2 changes: 1 addition & 1 deletion css/ui.jqgrid.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* jqGrid 4.13.1-pre - free jqGrid: https://github.com/free-jqgrid/jqGrid
* Date: 2016-03-07
* Date: 2016-03-08
*/

/* Grid */
Expand Down
2 changes: 1 addition & 1 deletion js/grid.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Dual licensed under the MIT and GPL licenses
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl-2.0.html
* Date: 2016-03-07
* Date: 2016-03-08
*/
//jsHint options
/*jshint eqnull:true */
Expand Down
14 changes: 13 additions & 1 deletion js/grid.custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
stringResult: false,
groupOp: "AND",
defaultSearch: "bw",
idMode: "new", // support "old", "compatibility", "new"
searchOperators: false,
resetIcon: "x",
applyLabelClasses: true,
Expand All @@ -253,7 +254,18 @@
dataFieldClass = getGuiStyles.call($t, "filterToolbar.dataField"),
currentFilters,
getId = function (cmName) {
return "gs_" + p.idPrefix + cmName;
var prefix = "gs_";
switch (o.idMode) {
case "compatibility":
prefix += p.idPrefix;
break;
case "new":
prefix += p.id + "_";
break;
default: // "old"
break;
}
return prefix + cmName;
},
getIdSel = function (cmName) {
return "#" + getId(cmName);
Expand Down
673 changes: 337 additions & 336 deletions js/jquery.jqgrid.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/jquery.jqgrid.min.map

Large diffs are not rendered by default.

38 changes: 25 additions & 13 deletions js/jquery.jqgrid.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Dual licensed under the MIT and GPL licenses
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl-2.0.html
* Date: 2016-03-07
* Date: 2016-03-08
*/
//jsHint options
/*jshint eqnull:true */
Expand Down Expand Up @@ -8827,6 +8827,7 @@
stringResult: false,
groupOp: "AND",
defaultSearch: "bw",
idMode: "new", // support "old", "compatibility", "new"
searchOperators: false,
resetIcon: "x",
applyLabelClasses: true,
Expand All @@ -8844,11 +8845,22 @@
highlightClass = getGuiStyles.call($t, "states.select"),
dataFieldClass = getGuiStyles.call($t, "filterToolbar.dataField"),
currentFilters,
getId = function (cmName) {
return "gs_" + p.idPrefix + cmName;
getFiledId = function (cmName) {
var prefix = "gs_";
switch (o.idMode) {
case "compatibility":
prefix += p.idPrefix;
break;
case "new":
prefix += p.id + "_";
break;
default: // "old"
break;
}
return prefix + cmName;
},
getIdSel = function (cmName) {
return "#" + getId(cmName);
getFiledIdSel = function (cmName) {
return "#" + getFiledId(cmName);
},
parseFilter = function () {
var j, filters = p.postData.filters, filter = {}, rules, rule,
Expand Down Expand Up @@ -8889,7 +8901,7 @@
var sdata = {}, j = 0, sopt = {};
$.each(colModel, function () {
var cm = this, nm = cm.index || cm.name, v, so, searchoptions = cm.searchoptions || {},
$elem = $(getIdSel(cm.name), (cm.frozen === true && p.frozenColumns === true) ? grid.fhDiv : grid.hDiv),
$elem = $(getFiledIdSel(cm.name), (cm.frozen === true && p.frozenColumns === true) ? grid.fhDiv : grid.hDiv),
getFormaterOption = function (optionName, formatter) {
var formatoptions = cm.formatoptions || {};
return formatoptions[optionName] !== undefined ?
Expand Down Expand Up @@ -9010,7 +9022,7 @@
var sdata = {}, j = 0, nm;
trigger = (typeof trigger !== "boolean") ? true : trigger;
$.each(colModel, function () {
var v, cm = this, $elem = $(getIdSel(cm.name), (cm.frozen === true && p.frozenColumns === true) ? grid.fhDiv : grid.hDiv),
var v, cm = this, $elem = $(getFiledIdSel(cm.name), (cm.frozen === true && p.frozenColumns === true) ? grid.fhDiv : grid.hDiv),
isSindleSelect, searchoptions = cm.searchoptions || {};
if (searchoptions.defaultValue !== undefined) { v = searchoptions.defaultValue; }
nm = cm.index || cm.name;
Expand Down Expand Up @@ -9270,7 +9282,7 @@
}

if (soptions1.defaultValue !== undefined) { $select.val(soptions1.defaultValue); }
$select.attr({ name: cm1.index || cm1.name, id: getId(cm1.name) });
$select.attr({ name: cm1.index || cm1.name, id: getFiledId(cm1.name) });
if (soptions1.attr) { $select.attr(soptions1.attr); }
$select.addClass(dataFieldClass);
$select.css({ width: "100%" });
Expand Down Expand Up @@ -9306,7 +9318,7 @@
if (oSv) {
var elem = document.createElement("select");
elem.style.width = "100%";
$(elem).attr({ name: cm.index || cm.name, id: getId(cm.name) });
$(elem).attr({ name: cm.index || cm.name, id: getFiledId(cm.name) });
var sv, ov, key, k, isNoFilterValueExist;
if (typeof oSv === "string") {
so = oSv.split(delim);
Expand Down Expand Up @@ -9365,7 +9377,7 @@
case "text":
var df = soptions.defaultValue !== undefined ? soptions.defaultValue : "";

$("td", stbl).eq(1).append("<input type='text' class='" + dataFieldClass + "' name='" + (cm.index || cm.name) + "' id='" + getId(cm.name) + "' value='" + df + "'/>");
$("td", stbl).eq(1).append("<input type='text' class='" + dataFieldClass + "' name='" + (cm.index || cm.name) + "' id='" + getFiledId(cm.name) + "' value='" + df + "'/>");
$(thd).append(stbl);

if (soptions.attr) { $("input", thd).attr(soptions.attr); }
Expand Down Expand Up @@ -9403,7 +9415,7 @@
}
break;
case "custom":
$("td", stbl).eq(1).append("<span style='width:100%;padding:0;box-sizing:border-box;' class='" + dataFieldClass + "' name='" + (cm.index || cm.name) + "' id='" + getId(cm.name) + "'/>");
$("td", stbl).eq(1).append("<span style='width:100%;padding:0;box-sizing:border-box;' class='" + dataFieldClass + "' name='" + (cm.index || cm.name) + "' id='" + getFiledId(cm.name) + "'/>");
$(thd).append(stbl);
try {
if ($.isFunction(soptions.custom_element)) {
Expand Down Expand Up @@ -9495,7 +9507,7 @@
for (cmName in newFilters) {
if (newFilters.hasOwnProperty(cmName)) {
filter = newFilters[cmName];
$input = $(getIdSel(cmName));
$input = $(getFiledIdSel(cmName));
$input.val(filter.data);
$searchOper = $input.closest(".ui-search-input")
.siblings(".ui-search-oper")
Expand All @@ -9507,7 +9519,7 @@
for (i = 0; i < p.colModel.length; i++) {
cmName = p.colModel[i].name;
if (!newFilters.hasOwnProperty(cmName)) {
$(getIdSel(cmName)).val("");
$(getFiledIdSel(cmName)).val("");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/min/grid.base.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7cc6120

Please sign in to comment.