Skip to content

Commit

Permalink
Add idSeparator option of form deleting. Add array of rowids as the l…
Browse files Browse the repository at this point in the history
…ast parameter of some callbacks and jqGridDeleteAfterComplete event

1) Default value of new `idSeparator` option is `","`, which corresponds old behavior.

2) Add array of rowids as additional parameter of callbacks `afterComplete`, `afterSubmit`, `beforeSubmit`, `onclickSubmit` and `url` and the event `jqGridDeleteAfterComplete`. It's important that array of rowids contains **rowids**, which could have id prefix specified by the option `idPrefix`. If one needs to have pure ids instead of rowids, then one has to cut the prefix from every element of **rowids** array.
  • Loading branch information
OlegKi committed Oct 22, 2017
1 parent e8463fa commit 425a03f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
19 changes: 10 additions & 9 deletions js/grid.formedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,7 @@
//jqModal : true,
closeOnEscape: false,
delData: {},
idSeparator: ",",
onClose: null,
ajaxDelOptions: {},
processing: false,
Expand Down Expand Up @@ -1827,7 +1828,7 @@
if (!$.isArray(rowids)) { rowids = [String(rowids)]; }
if ($(themodalSelector)[0] !== undefined) {
if (!deleteFeedback("beforeInitData", $(dtbl))) { return; }
$("#DelData>td", dtbl).text(rowids.join()).data("rowids", rowids);
$("#DelData>td", dtbl).text(rowids.join(o.idSeparator)).data("rowids", rowids);
$("#DelError", dtbl).hide();
if (o.processing === true) {
o.processing = false;
Expand All @@ -1850,7 +1851,7 @@
tbl += "<table class='DelTable'><tbody>";
// error data
tbl += "<tr id='DelError' style='display:none'><td class='" + errorClass + "'></td></tr>";
tbl += "<tr id='DelData' style='display:none'><td >" + rowids.join() + "</td></tr>";
tbl += "<tr id='DelData' style='display:none'><td >" + rowids.join(o.idSeparator) + "</td></tr>";
tbl += "<tr><td class='delmsg'>" + o.msg + "</td></tr>";
// buttons at footer
tbl += "</tbody></table></div></div>";
Expand All @@ -1876,8 +1877,8 @@
postdata = $delData.text(), //the pair is name=val1,val2,...
formRowIds = $delData.data("rowids"),
cs = {};
if ($.isFunction(o.onclickSubmit)) { cs = o.onclickSubmit.call($t, o, postdata) || {}; }
if ($.isFunction(o.beforeSubmit)) { ret = o.beforeSubmit.call($t, postdata) || ret; }
if ($.isFunction(o.onclickSubmit)) { cs = o.onclickSubmit.call($t, o, postdata, formRowIds) || {}; }
if ($.isFunction(o.beforeSubmit)) { ret = o.beforeSubmit.call($t, postdata, formRowIds) || ret; }
if (ret[0] && !o.processing) {
o.processing = true;
opers = p.prmNames;
Expand All @@ -1892,13 +1893,13 @@
postdata[pk] = jgrid.stripPref(p.idPrefix, postdata[pk]);
}
}
postd[idname] = postdata.join();
postd[idname] = postdata.join(o.idSeparator);
$(this).addClass(activeClass);
var url = o.url || p.editurl,
ajaxOptions = $.extend({
url: $.isFunction(url) ? url.call($t, postd[idname], postd, o) : url,
url: $.isFunction(url) ? url.call($t, postd[idname], postd, o, formRowIds) : url,
type: o.mtype,
data: $.isFunction(o.serializeDelData) ? o.serializeDelData.call($t, postd) : postd,
data: $.isFunction(o.serializeDelData) ? o.serializeDelData.call($t, postd, formRowIds) : postd,
complete: function (jqXHR, textStatus) {
var i;
$self.jqGrid("progressBar", { method: "hide", loadtype: o.delui });
Expand All @@ -1914,7 +1915,7 @@
// data is posted successful
// execute aftersubmit with the returned data from server
if ($.isFunction(o.afterSubmit)) {
ret = o.afterSubmit.call($t, jqXHR, postd) || [true];
ret = o.afterSubmit.call($t, jqXHR, postd, formRowIds) || [true];
}
}
if (ret[0] === false) {
Expand All @@ -1935,7 +1936,7 @@
$self.trigger("reloadGrid", [$.extend({}, o.reloadGridOptions || {})]);
}
setTimeout(function () {
deleteFeedback("afterComplete", jqXHR, postdata, $(dtbl));
deleteFeedback("afterComplete", jqXHR, postdata, $(dtbl), formRowIds);
}, 50);
}
o.processing = false;
Expand Down
13 changes: 7 additions & 6 deletions ts/free-jqgrid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,13 +858,13 @@ declare namespace FreeJqGrid {
[propName: string]: any; // allow to have any number of other properties
}
interface FormDeletingOptions extends DeleteFormLocaleOptions {
afterComplete?: (this: BodyTable, jqXhr: JQueryXHR, postdata: Object | string, $form: JQuery) => void;
afterComplete?: (this: BodyTable, jqXhr: JQueryXHR, postdata: Object | string, $form: JQuery, rowids: string[]) => void;
afterShowForm?: (this: BodyTable, $form: JQuery) => void;
afterSubmit?: (this: BodyTable, $form: JQuery) => void;
afterSubmit?: (this: BodyTable, jqXhr: JQueryXHR, postdata: Object | string, rowids: string[]) => void;
ajaxDelOptions?: JQueryAjaxSettings;
beforeInitData?: (this: BodyTable, $form: JQuery) => BooleanFeedbackValues;
beforeShowForm?: (this: BodyTable, $form: JQuery) => void;
beforeSubmit?: (this: BodyTable, postdata: Object | string, $form: JQuery) => [true] | [true, any] | undefined | [false, string];
beforeSubmit?: (this: BodyTable, postdata: Object | string, rowids: string[]) => [true] | [true, any] | undefined | [false, string];
cancelicon?: FormIcon; // [true,"left","fa fa-ban"]
closeOnEscape?: boolean;
commonIconClass?: string; // "fa"
Expand All @@ -876,9 +876,10 @@ declare namespace FreeJqGrid {
delui?: LoadType; // "disable"
drag?: boolean;
height?: number | "auto" | "100%" | string; // "auto"
idSeparator?: string; // ","
left?: number;
mtype?: string; // "POST"
onclickSubmit?: (this: BodyTable, options: FormDeletingOptions, postdata: Object | string) => Object | string;
onclickSubmit?: (this: BodyTable, options: FormDeletingOptions, postdata: Object | string, rowids: string[]) => Object | string;
onClose?: (this: BodyTable, selector: string | Element | JQuery) => boolean;
processing?: boolean; // internal used
reloadAfterSubmit?: boolean;
Expand All @@ -887,7 +888,7 @@ declare namespace FreeJqGrid {
resize?: boolean;
serializeDelData?: (this: BodyTable, postdata: Object | string) => Object | string;
top?: number;
url?: string | ((this: BodyTable, rowid: string, postdata: Object | string, options: FormDeletingOptions) => string);
url?: string | ((this: BodyTable, rowid: string, postdata: Object | string, options: FormDeletingOptions, rowids: string[]) => string);
useDataProxy?: boolean;
width?: number | "auto" | "100%" | string; // "auto"
[propName: string]: any; // allow to have any number of other properties
Expand Down Expand Up @@ -2053,7 +2054,7 @@ interface JQuery {

// form deleting events
on(eventName: "jqGridDeleteAfterShowForm", handler: (eventObject: JQueryEventObject, $form: JQuery) => void): FreeJqGrid.JQueryJqGrid;
on(eventName: "jqGridAddEditAfterComplete", handler: (eventObject: JQueryEventObject, jqXhr: JQueryXHR, postdata: Object | string, $form: JQuery) => void): FreeJqGrid.JQueryJqGrid;
on(eventName: "jqGridDeleteAfterComplete", handler: (eventObject: JQueryEventObject, jqXhr: JQueryXHR, postdata: Object | string, $form: JQuery, rowids: string[]) => void): FreeJqGrid.JQueryJqGrid;
on(eventName: "jqGridDeleteBeforeInitData", handler: (eventObject: JQueryEventObject, $form: JQuery) => FreeJqGrid.BooleanFeedbackValues): FreeJqGrid.JQueryJqGrid;
on(eventName: "jqGridDeleteBeforeShowForm", handler: (eventObject: JQueryEventObject, $form: JQuery) => void): FreeJqGrid.JQueryJqGrid;

Expand Down

0 comments on commit 425a03f

Please sign in to comment.