Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 756067a

Browse files
authored
Merge pull request gridstack#2378 from DigitagDev/add-a-non-removable-class
add a class that defines a non removable grid item
2 parents 1cbf5d8 + e15dc8c commit 756067a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/gridstack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export class GridStack {
286286
},
287287
removableOptions: {
288288
accept: opts.itemClass ? '.' + opts.itemClass : gridDefaults.removableOptions.accept,
289+
decline: gridDefaults.removableOptions.decline
289290
},
290291
};
291292
if (el.getAttribute('gs-animate')) { // default to true, but if set to false use that instead
@@ -2038,7 +2039,7 @@ export class GridStack {
20382039
/** @internal mark item for removal */
20392040
private _itemRemoving(el: GridItemHTMLElement, remove: boolean) {
20402041
let node = el ? el.gridstackNode : undefined;
2041-
if (!node || !node.grid) return;
2042+
if (!node || !node.grid || el.classList.contains(this.opts.removableOptions.decline)) return;
20422043
remove ? node._isAboutToRemove = true : delete node._isAboutToRemove;
20432044
remove ? el.classList.add('grid-stack-item-removing') : el.classList.remove('grid-stack-item-removing');
20442045
}

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const gridDefaults: GridStackOptions = {
2525
oneColumnSize: 768,
2626
placeholderClass: 'grid-stack-placeholder',
2727
placeholderText: '',
28-
removableOptions: { accept: '.grid-stack-item' },
28+
removableOptions: { accept: '.grid-stack-item' ,decline:'grid-stack-non-removable'},
2929
resizable: { handles: 'se' },
3030
rtl: 'auto',
3131

@@ -39,6 +39,7 @@ export const gridDefaults: GridStackOptions = {
3939
// removable: false,
4040
// staticGrid: false,
4141
// styleInHead: false,
42+
//removable
4243
};
4344

4445
/** default dragIn options */
@@ -334,6 +335,7 @@ export interface DDResizeOpt {
334335
export interface DDRemoveOpt {
335336
/** class that can be removed (default?: '.' + opts.itemClass) */
336337
accept?: string;
338+
decline?: string;
337339
}
338340

339341
/** Drag&Drop dragging options */

0 commit comments

Comments
 (0)