Skip to content

Instantly share code, notes, and snippets.

@caca9512
Last active December 17, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caca9512/5662735 to your computer and use it in GitHub Desktop.
Save caca9512/5662735 to your computer and use it in GitHub Desktop.
jtable.org hijack for multiselect
$.hik.jtable.prototype._fillDropDownListWithOptions = function ($select, options, value) {
var fieldName = $select.attr("name");
var field = this.options.fields[fieldName];
if (field.type == "multi")
{
$select.empty().attr("multiple", "multiple");
for (var i = 0; i < options.length; i++)
{
var selected = false;
if (value != undefined)
{
for (var j = 0; j < value.length; j++)
{
if (value[j] == options[i].Value)
{
selected = true;
break;
}
}
}
else
{
selected = false;
}
//$select.append('<option ' + (selected ? ' selected = "selected" ' : '') + ' > ' + options[i].DisplayText + '</option>');
$('<option ' + (selected ? ' selected = "selected" ' : '') + '>' + options[i].DisplayText + '</option>').val(options[i].Value).appendTo($select);
}
}
else
{
$select.empty();
for (var i = 0; i < options.length; i++) {
//$select.append('<option ' + (options[i].Value == value ? ' selected="selected" ' : '') + '>' + options[i].DisplayText + '</option>');
$('<option' + (options[i].Value == value ? ' selected = "selected"' : '') + '>' + options[i].DisplayText + '</option>').val(options[i].Value).appendTo($select);
}
}
};
$.hik.jtable.prototype._convertQueryStringToObject = function (queryString) {
var jsonObj = {};
var e,
a = /\+/g,
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); };
while (e = r.exec(queryString)) {
// alert(e);
// alert(d(e[1]));
if (jsonObj[d(e[1])] === undefined) {
//alert(jsonObj[d(e[1])]);
jsonObj[d(e[1])] = d(e[2]);
}
else {
if (!(jsonObj[d(e[1])] instanceof Array)) {
jsonObj[d(e[1])] = new Array(jsonObj[d(e[1])]);
}
jsonObj[d(e[1])][jsonObj[d(e[1])].length] = d(e[2]);
}
}
return jsonObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment