nr-grid
Version:
NR-Grid is basic a datagrid helper that uses Bootstrap and NgbBootstrap and developed for Angular applications.
993 lines • 52.6 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('lodash'), require('rxjs'), require('rxjs/operators'), require('@ng-bootstrap/ng-bootstrap'), require('date-fns/format'), require('@angular/common'), require('@angular/forms'), require('nr-select')) :
typeof define === 'function' && define.amd ? define('nr-grid', ['exports', '@angular/core', 'lodash', 'rxjs', 'rxjs/operators', '@ng-bootstrap/ng-bootstrap', 'date-fns/format', '@angular/common', '@angular/forms', 'nr-select'], factory) :
(global = global || self, factory(global['nr-grid'] = {}, global.ng.core, global.lodash, global.rxjs, global.rxjs.operators, global.ngBootstrap, global.format, global.ng.common, global.ng.forms, global.nrSelect));
}(this, (function (exports, core, lodash, rxjs, operators, ngBootstrap, format, common, forms, nrSelect) { 'use strict';
format = format && Object.prototype.hasOwnProperty.call(format, 'default') ? format['default'] : format;
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __createBinding(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}
function __exportStar(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
var NrGridService = /** @class */ (function () {
function NrGridService() {
}
NrGridService.ɵprov = core.ɵɵdefineInjectable({ factory: function NrGridService_Factory() { return new NrGridService(); }, token: NrGridService, providedIn: "root" });
NrGridService = __decorate([
core.Injectable({
providedIn: 'root'
})
], NrGridService);
return NrGridService;
}());
(function (NRGridColumnType) {
NRGridColumnType[NRGridColumnType["none"] = 0] = "none";
NRGridColumnType[NRGridColumnType["default"] = 1] = "default";
NRGridColumnType[NRGridColumnType["link"] = 2] = "link";
NRGridColumnType[NRGridColumnType["inlineEditor"] = 3] = "inlineEditor";
})(exports.NRGridColumnType || (exports.NRGridColumnType = {}));
(function (FilterType) {
FilterType[FilterType["default"] = 0] = "default";
FilterType[FilterType["date"] = 1] = "date";
FilterType[FilterType["dateRange"] = 2] = "dateRange";
FilterType[FilterType["yesNoRadio"] = 3] = "yesNoRadio";
FilterType[FilterType["typeHead"] = 4] = "typeHead";
FilterType[FilterType["numericRange"] = 5] = "numericRange";
FilterType[FilterType["dropdown"] = 6] = "dropdown";
})(exports.FilterType || (exports.FilterType = {}));
var NRGridComponent = /** @class */ (function () {
function NRGridComponent(modalService, cdr) {
var _this = this;
this.modalService = modalService;
this.cdr = cdr;
this.onPageChanged = new core.EventEmitter();
this.onEditClicked = new core.EventEmitter();
this.onDeleteClicked = new core.EventEmitter();
this.onFilterChanged = new core.EventEmitter();
this.onOrderChanged = new core.EventEmitter();
this.onRowClicked = new core.EventEmitter();
this.onRowValueChanged = new core.EventEmitter();
this.onCellLinkClicked = new core.EventEmitter();
this.onLimitChanged = new core.EventEmitter();
this.onCustomButtonClicked = new core.EventEmitter();
this.editingRows = {};
this.limitChangeOptions = {
searchable: false,
valueMember: 'id',
displayMember: 'text',
hideLabel: true
};
this.pages = [
{ id: 10, text: '10' },
{ id: 25, text: '25' },
{ id: 50, text: '50' },
{ id: 100, text: '100' },
];
this.ranges = {};
this.filterChanged = new rxjs.Subject();
this.rowFilterChange = new core.EventEmitter();
this.dataLoaded = new core.EventEmitter();
this.order = {};
this.typeheads = [];
this._rangeValue = '';
this.limit = 10;
this.filterChanged.pipe(operators.debounceTime(500)).subscribe(function (val) {
if (_this.go.dataSource) {
_this.go.dataSource.reload();
}
else {
_this.onFilterChanged.emit(_this.rowFilter);
}
});
}
Object.defineProperty(NRGridComponent.prototype, "rowFilter", {
get: function () {
return this._rowFilter;
},
set: function (value) {
this.changePage(1);
this._rowFilter = value;
this.rowFilterChange.emit(this._rowFilter);
},
enumerable: true,
configurable: true
});
NRGridComponent.prototype.changePage = function (page) {
if (this.options) {
this.options.page = page;
}
};
NRGridComponent.prototype.filteredColumns = function () {
var f = lodash.filter(this.go.columns, function (x) {
return !x.denied;
});
return lodash.filter(f, function (x) {
return !x.hide;
});
};
NRGridComponent.prototype.dataLoad = function (go) {
var _this = this;
go.loading = true;
if (go.dataSource.usePromise) {
go.dataSource.loader(go.dataSource.parent, this.rowFilter)
.then(function (r) {
go.data = r.data;
go.rowCount = r.rowCount;
go.loading = false;
_this.dataLoaded.emit(true);
if (r.summary) {
go.summary = r.summary;
}
})
.catch(function (e) {
go.loading = false;
console.log('qr-grid-data-load-error', e);
});
}
else {
go.dataSource.loader(this.go.dataSource.parent, this.rowFilter).subscribe(function (r) {
go.data = r.data;
go.rowCount = r.rowCount;
go.loading = false;
_this.dataLoaded.emit(true);
if (r.summary) {
go.summary = r.summary;
}
}, function (err) {
go.loading = false;
console.log('qr-grid-data-load-error', err);
});
}
};
NRGridComponent.prototype.ngOnInit = function () {
var _this = this;
if (!this.rowFilter) {
this.rowFilter = {};
}
if (this.options && !this.options.limit) {
this.options.limit = 10;
}
if (this.options && !this.options.loading) {
this.options.loading = true;
}
if (this.options && this.options.pager === undefined) {
this.options.pager = true;
}
this.go = this.options;
if (!this.go.data) {
this.go.data = [];
}
if (!this.go.page) {
this.go.page = 1;
}
if (!this.go.limit) {
this.go.limit = 10;
}
if (!this.go.rowCount) {
this.go.rowCount = 0;
}
if (!this.go.bootstrapTableClass) {
this.go.bootstrapTableClass = 'table-bordered';
}
this.columns = this.filteredColumns();
this.loadDropdownData();
if (this.go.dataSource) {
this.go.dataSource.reload = function () {
_this.editingRows = {};
return _this.dataLoad(_this.go);
};
if (!this.go.dataSource.manualLoading) {
this.go.dataSource.reload();
}
else {
this.go.loading = false;
}
}
};
NRGridComponent.prototype.loadDropdownData = function () {
var my = this;
lodash.each(this.go.columns, function (x) {
if (x.dropdownDataService) {
my.loadLookupData(x);
}
});
};
NRGridComponent.prototype.filterChange = function () {
this.changePage(1);
this.filterChanged.next(this.rowFilter);
this.loadDropdownData();
};
NRGridComponent.prototype.pageChange = function (val) {
if (this.go.dataSource) {
this.go.page = val;
this.go.dataSource.reload();
}
this.onPageChanged.emit(val);
};
NRGridComponent.prototype.editClicked = function (rowData) {
this.onEditClicked.emit(lodash.clone(rowData));
};
NRGridComponent.prototype.checkEditButtonOption = function (rowData) {
if (!this.go.actionButtonsOptions) {
return true;
}
else if (!this.go.actionButtonsOptions.edit) {
return false;
}
if (typeof this.go.actionButtonsOptions.edit == 'boolean') {
return this.go.actionButtonsOptions.edit;
}
else {
return this.go.actionButtonsOptions.edit(rowData);
}
};
NRGridComponent.prototype.checkDeleteButtonOption = function (rowData) {
if (!this.go.actionButtonsOptions) {
return true;
}
else if (!this.go.actionButtonsOptions.delete) {
return false;
}
if (typeof this.go.actionButtonsOptions.delete == 'boolean') {
return this.go.actionButtonsOptions.delete;
}
else {
return this.go.actionButtonsOptions.delete(rowData);
}
};
NRGridComponent.prototype.deleteClicked = function (rowData) {
this.activeDeleteModal = this.modalService.open(this.deleteModal, { centered: true });
this.deleteData = rowData;
};
NRGridComponent.prototype.submitDelete = function () {
this.onDeleteClicked.emit(this.deleteData);
this.activeDeleteModal.close();
};
NRGridComponent.prototype.linkClicked = function (data) {
this.onCellLinkClicked.emit(data);
};
NRGridComponent.prototype.isDefaultCell = function (t) {
return !t || (t == exports.NRGridColumnType.default || t == exports.NRGridColumnType.inlineEditor);
};
NRGridComponent.prototype.isLinkCell = function (t) {
return t === exports.NRGridColumnType.link;
};
NRGridComponent.prototype.toggleOrder = function (column) {
var columnKey = column.orderKey ? column.orderKey : column.name;
if (this.order.column === columnKey) {
this.order.desc = !this.order.desc;
}
else {
this.order.desc = false;
}
this.order.column = columnKey;
this.onOrderChanged.emit(this.order);
};
NRGridComponent.prototype.rowValueChanged = function (e) {
this.onRowValueChanged.emit(e);
};
NRGridComponent.prototype.rowClicked = function (rowData) {
if (this.go.rowClickAction && this.go.rowClickAction.enable) {
this.onRowClicked.emit(rowData);
}
};
NRGridComponent.prototype.isFilterDefault = function (val) {
return val === exports.FilterType.default;
};
NRGridComponent.prototype.isFilterDateRange = function (val) {
return val === exports.FilterType.dateRange;
};
NRGridComponent.prototype.isFilterYesNo = function (val) {
return val == exports.FilterType.yesNoRadio;
};
NRGridComponent.prototype.isFilterTypehead = function (val) {
return val == exports.FilterType.typeHead;
};
NRGridComponent.prototype.isFilterDropdown = function (c) {
return c.filterType == exports.FilterType.dropdown;
};
NRGridComponent.prototype.isFilterNumericRange = function (val) {
return val == exports.FilterType.numericRange;
};
NRGridComponent.prototype.selectTypeheadItem = function ($event, key) {
this.rowFilter[key] = $event.item;
this.filterChange();
};
NRGridComponent.prototype.onDateSelection = function (date, filterKey) {
if (!this.fromDate && !this.toDate) {
this.fromDate = date;
}
else if (this.fromDate && !this.toDate && date.after(this.fromDate)) {
this.toDate = date;
}
else {
this.toDate = null;
this.fromDate = date;
}
if (this.fromDate && this.toDate) {
var bs = this.fromDate;
var be = this.toDate;
var s = new Date(bs.year, bs.month - 1, bs.day);
var e = new Date(be.year, be.month - 1, be.day);
this._rangeValue = format(s, 'dd/MM/yyyy') + ' - ' + format(e, 'dd/MM/yyyy');
this.rangePicker.toggle();
this.rowFilter[filterKey] = s.toISOString() + ',' + e.toISOString();
this.filterChange();
}
};
NRGridComponent.prototype.rangeValue = function () {
return this._rangeValue;
};
NRGridComponent.prototype.isHovered = function (date) {
return this.fromDate && !this.toDate && this.hoveredDate && date.after(this.fromDate) && date.before(this.hoveredDate);
};
NRGridComponent.prototype.isInside = function (date) {
return date.after(this.fromDate) && date.before(this.toDate);
};
NRGridComponent.prototype.isRange = function (date) {
return date.equals(this.fromDate) || date.equals(this.toDate) || this.isInside(date) || this.isHovered(date);
};
NRGridComponent.prototype.getFilterKey = function (c) {
return c.filterKey ? c.filterKey : c.name;
};
NRGridComponent.prototype.rangeChanged = function (c) {
var key = this.getFilterKey(c);
var startKey = key + '___start';
var endKey = key + '___end';
var start = this.ranges[startKey];
var end = this.ranges[endKey];
this.rowFilter[key] = (start ? start : '') + '___' + (end ? end : '');
this.filterChange();
};
NRGridComponent.prototype.limitChanged = function (limit) {
this.limit = Number(limit.value ? limit.value : limit);
if (this.options.dataSource) {
this.options.dataSource.reload();
}
this.onLimitChanged.emit(this.limit);
};
NRGridComponent.prototype.loadLookupData = function (c) {
if (!c.dropdownData) {
c.dropdownDataService.subscribe(function (result) {
c.dropdownData = lodash.map(result.data, function (x) {
return {
id: x.id,
text: x.name
};
});
});
}
};
NRGridComponent.prototype.customButtonClick = function (button, row) {
this.onCustomButtonClicked.emit({
button: button,
data: row
});
};
NRGridComponent.prototype.inlineEditorOn = function (cr, rowIndex, rowValue) {
if (cr.type == exports.NRGridColumnType.inlineEditor) {
this.editingRows['row-' + rowIndex + '-col-' + cr.name] = {
firstValue: rowValue[cr.name]
};
this.cdr.detectChanges();
var e = document.getElementById('row-' + rowIndex + '-col-' + cr.name);
if (e) {
e.focus();
}
}
};
NRGridComponent.prototype.inlineEditorOff = function (cr, rowIndex, rowValue, toggleEvent, revert) {
if (rowValue === void 0) { rowValue = undefined; }
if (toggleEvent === void 0) { toggleEvent = false; }
if (revert === void 0) { revert = false; }
if (revert) {
rowValue[cr.name] = this.editingRows['row-' + rowIndex + '-col-' + cr.name].firstValue;
}
this.editingRows['row-' + rowIndex + '-col-' + cr.name] = undefined;
if (!revert && toggleEvent) {
this.rowValueChanged({
column: cr,
row: rowValue
});
}
};
NRGridComponent.ctorParameters = function () { return [
{ type: ngBootstrap.NgbModal },
{ type: core.ChangeDetectorRef }
]; };
__decorate([
core.Input()
], NRGridComponent.prototype, "options", void 0);
__decorate([
core.Input()
], NRGridComponent.prototype, "loading", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onPageChanged", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onEditClicked", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onDeleteClicked", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onFilterChanged", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onOrderChanged", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onRowClicked", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onRowValueChanged", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onCellLinkClicked", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onLimitChanged", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "onCustomButtonClicked", void 0);
__decorate([
core.ViewChild('deleteModal', { static: false })
], NRGridComponent.prototype, "deleteModal", void 0);
__decorate([
core.ViewChild('rangePicker', { static: false })
], NRGridComponent.prototype, "rangePicker", void 0);
__decorate([
core.Input()
], NRGridComponent.prototype, "columnHeaderTemplate", void 0);
__decorate([
core.Input()
], NRGridComponent.prototype, "footerTemplate", void 0);
__decorate([
core.Input()
], NRGridComponent.prototype, "rowFilter", null);
__decorate([
core.Output()
], NRGridComponent.prototype, "rowFilterChange", void 0);
__decorate([
core.Output()
], NRGridComponent.prototype, "dataLoaded", void 0);
NRGridComponent = __decorate([
core.Component({
selector: 'nr-grid',
template: "<div class=\"nr-grid\">\n <div class=\"table-responsive\">\n <table class=\"table {{options.bootstrapTableClass}} mb-0\">\n <thead>\n <tr>\n <th *ngFor=\"let c of columns\" class=\"nr-order-trigger\" (click)=\"toggleOrder(c)\"\n [ngClass]=\"{'text-right': c.alignment == 'right' }\"\n [ngStyle]=\"{'width': c.width != undefined ? c.width : 'auto' }\">\n\n <ng-container *ngTemplateOutlet=\"columnHeaderTemplate; context: {column: c}\">\n\n </ng-container>\n <ng-container *ngIf=\"!columnHeaderTemplate\">\n {{c.title}}\n </ng-container>\n <span class=\"nr-grid-orderer\"\n *ngIf=\"order.column === (c.orderKey != null ? c.orderKey : c.name)\">\n <i *ngIf=\"!order.desc\" class=\"fa fa-arrow-up\"></i>\n <i *ngIf=\"order.desc\" class=\"fa fa-arrow-down\"></i>\n </span>\n </th>\n <th *ngIf=\"go.actionButtons\"\n [ngStyle]=\"{'width': (90 + ((go.buttons ? go.buttons.length : 0) * 25)) + 'px' }\"></th>\n </tr>\n <tr class=\"filter-row\" *ngIf=\"go.filterRowEnabled\">\n <td *ngFor=\"let c of columns\">\n <ng-container *ngIf=\"!c.filterDisable\">\n <input *ngIf=\"!c.filterType || isFilterDefault(c.filterType)\" type=\"text\" placeholder=\"Filter\"\n class=\"filter-control\" [(ngModel)]=\"rowFilter[getFilterKey(c)]\"\n (ngModelChange)=\"filterChange()\">\n <input *ngIf=\"isFilterDateRange(c.filterType)\" type=\"text\" class=\"btn-light-disable\"\n ngbDatepicker\n #rangePicker=\"ngbDatepicker\"\n (dateSelect)=\"onDateSelection($event, getFilterKey(c))\"\n [dayTemplate]=\"dayTemplate\"\n [displayMonths]=\"2\" outsideDays=\"visible\" (focus)=\"rangePicker.toggle()\"\n [autoClose]=\"false\"\n placeholder=\"Filter\"\n [value]=\"rangeValue()\"\n class=\"filter-control\">\n <div *ngIf=\"isFilterNumericRange(c.filterType)\" class=\"range-selector\">\n <input type=\"text\" class=\"filter-control\" placeholder=\"Grather\"\n [(ngModel)]=\"ranges[getFilterKey(c) + '___start']\" (ngModelChange)=\"rangeChanged(c)\">\n <input type=\"text\" class=\"filter-control\" placeholder=\"Lower\"\n [(ngModel)]=\"ranges[getFilterKey(c) + '___end']\" (ngModelChange)=\"rangeChanged(c)\">\n </div>\n\n <nr-select *ngIf=\"isFilterDropdown(c)\" [(value)]=\"rowFilter[getFilterKey(c)]\" [options]=\"c.selectOptions\"\n label=\"Select\" (valueChange)=\"filterChange()\"></nr-select>\n <div *ngIf=\"isFilterYesNo(c.filterType)\" class=\"btn-group btn-group-toggle\" ngbRadioGroup\n name=\"radioBasic\"\n [(ngModel)]=\"rowFilter[getFilterKey(c)]\" (ngModelChange)=\"filterChange()\">\n <label ngbButtonLabel class=\"btn-primary btn-xs\">\n <input ngbButton type=\"radio\" [value]=\"true\"> Yes\n </label>\n <label ngbButtonLabel class=\"btn-primary btn-xs\">\n <input ngbButton type=\"radio\" [value]=\"false\"> No\n </label>\n </div>\n </ng-container>\n </td>\n <td *ngIf=\"go.actionButtons\"></td>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let r of go.data; let rowIndex=index;\"\n class=\"data-row\"\n [ngClass]=\"{'nr-row-clickable': go.rowClickAction && go.rowClickAction.enable}\"\n (click)=\"rowClicked(r)\">\n <td *ngFor=\"let cr of columns\"\n [ngClass]=\"{'text-right': cr.alignment == 'right', 'padding-none': editingRows['row-' + rowIndex + '-col-' + cr.name]}\">\n\n <div *ngIf=\"cr.formatter && !isLinkCell(cr.type)\">\n {{r[cr.name]|valueFormat: cr.formatter}}\n </div>\n\n <div class=\"default-view\"\n *ngIf=\"!cr.formatter && isDefaultCell(cr.type) && !editingRows['row-' + rowIndex + '-col-' + cr.name]\"\n [innerHTML]=\"cr.format ? cr.format({row: r, value: r[cr.name], parent: go.parent }) : r[cr.name]\"\n (click)=\"inlineEditorOn(cr, rowIndex, r)\"></div>\n\n <div *ngIf=\"isLinkCell(cr.type)\">\n <a href=\"javascript:void(0)\" (click)=\"linkClicked({row: r, column: cr})\"\n class=\"{{cr.link && cr.link.classes ? cr.link.classes : ''}}\"\n [ngbTooltip]=\"cr.link && cr.link.tooltip ? cr.link.tooltip : ''\">\n <i *ngIf=\"cr.link && cr.link.icon\" class=\"{{cr.link.icon}}\"></i>\n\n <span *ngIf=\"!cr.formatter\"\n [innerHTML]=\"cr.format ? cr.format({row: r, value: r[cr.name], parent: go.parent}) : r[cr.name]\"></span>\n <span *ngIf=\"cr.formatter\">{{r[cr.name]|valueFormat: cr.formatter}}</span>\n </a>\n </div>\n <div *ngIf=\"editingRows['row-' + rowIndex + '-col-' + cr.name]\">\n <div class=\"nr-inline-editor\">\n <input [id]=\"'row-' + rowIndex + '-col-' + cr.name\" type=\"text\" [(ngModel)]=\"r[cr.name]\"/>\n <div class=\"nr-inline-editor-buttons\">\n <button class=\"btn btn-sm btn-primary\" type=\"button\" (click)=\"inlineEditorOff(cr, rowIndex, r, true)\">\n Save\n </button>\n <button class=\"btn btn-sm btn-secondary\" type=\"button\"\n (click)=\"inlineEditorOff(cr, rowIndex, r, false, true)\">Cancel\n </button>\n </div>\n </div>\n </div>\n </td>\n <td class=\"action-buttons-container\" *ngIf=\"go.actionButtons\">\n <ng-container *ngFor=\"let b of go.buttons\">\n <a href=\"javascript:void(0);\" (click)=\"customButtonClick(b, r)\" ngbTooltip=\"{{b.tooltip}}\"\n *ngIf=\"!b.visible || (b.visible && b.visible(r))\">\n <i class=\"{{b.icon}}\"></i>\n </a>\n </ng-container>\n <a href=\"javascript:void(0);\" (click)=\"editClicked(r)\" ngbTooltip=\"Edit\"\n *ngIf=\"!go.actionButtonsOptions || checkEditButtonOption(r)\">\n <i class=\"fa fa-pencil\"></i>\n </a>\n <a href=\"javascript:void(0);\" (click)=\"deleteClicked(r)\" ngbTooltip=\"Delete\"\n *ngIf=\"!go.actionButtonsOptions || checkDeleteButtonOption(r)\">\n <i class=\"fa fa-trash\"></i>\n </a>\n </td>\n </tr>\n <tr *ngIf=\"go.data == undefined || go.data.length == 0\">\n <td [colSpan]=\"columns.length + (go.actionButtons ? 1 : 0)\">\n <div style=\"padding: 20px; text-align: center\">\n No data\n </div>\n </td>\n </tr>\n </tbody>\n <tfoot *ngIf=\"go.summary && !go.hideSummary\">\n <tr>\n <th *ngFor=\"let cr of columns\" [ngClass]=\"{'text-right': cr.alignment == 'right' }\">\n <ng-container *ngIf=\"!cr.hideFromSummary\">\n <div *ngIf=\"cr.formatter\">\n {{go.summary[cr.name]|valueFormat: cr.formatter}}\n </div>\n\n <div *ngIf=\"isDefaultCell(cr.type) && (!cr.formatter)\"\n [innerHTML]=\"cr.format ? cr.format({row: go.summary, value: go.summary[cr.name], parent: go.parent}) : go.summary[cr.name]\"></div>\n\n <div *ngIf=\"isLinkCell(cr.type) && (!cr.formatter)\">\n <a href=\"javascript:void(0)\" (click)=\"linkClicked({row: go.summary, column: cr})\"\n class=\"{{cr.link.classes ? cr.link.classes : ''}}\"\n [ngbTooltip]=\"cr.link && cr.link.tooltip ? cr.link.tooltip : ''\">\n <i *ngIf=\"cr.link.icon\" class=\"{{cr.link.icon}}\"></i>\n <span\n [innerHTML]=\"cr.format ? cr.format({row: go.summary, value: go.summary[cr.name], parent: go.parent}) : go.summary[cr.name]\"></span>\n </a>\n </div>\n </ng-container>\n </th>\n </tr>\n </tfoot>\n </table>\n\n </div>\n <ng-container *ngTemplateOutlet=\"footerTemplate;\">\n\n </ng-container>\n <div class=\"nr-grid-footer row\" *ngIf=\"go.pager\">\n <div class=\"col-md-12\">\n <ngb-pagination class=\"float-right\" [collectionSize]=\"go.rowCount\" [(page)]=\"go.page\" [maxSize]=\"10\"\n [pageSize]=\"go.limit\" (pageChange)=\"pageChange($event)\"></ngb-pagination>\n <div class=\"float-right limit-selector\" style=\"min-width: 150px; width: 150px\">\n <nr-select class=\"float-right\" [data]=\"pages\" [(value)]=\"go.limit\" label=\"Limit\" [options]=\"limitChangeOptions\"\n (valueChange)=\"limitChanged($event)\"></nr-select>\n </div>\n </div>\n </div>\n <div class=\"clearfix\"></div>\n</div>\n<ng-template #deleteModal let-modal>\n <div class=\"modal-header\">\n <h4 class=\"modal-title\" id=\"modal-basic-title\">Delete</h4>\n <button type=\"button\" class=\"close\" aria-label=\"Close\" (click)=\"modal.dismiss('Cross click')\">\n <span aria-hidden=\"true\">×</span>\n </button>\n </div>\n <div class=\"modal-body\">\n Data will be deleted, are you sure?\n </div>\n <div class=\"modal-footer\">\n <button type=\"submit\" class=\"btn btn-success\" (click)=\"submitDelete()\">Delete</button>\n <button type=\"button\" class=\"btn btn-secondary\" (click)=\"modal.dismiss('Cross click')\">Cancel</button>\n </div>\n</ng-template>\n<ng-template #dayTemplate let-date let-focused=\"focused\">\n <span class=\"custom-day\"\n [class.focused]=\"focused\"\n [class.range]=\"isRange(date)\"\n [class.faded]=\"isHovered(date) || isInside(date)\"\n (mouseenter)=\"hoveredDate = date\"\n (mouseleave)=\"hoveredDate = null\">\n {{ date.day }}\n </span>\n</ng-template>\n"
})
], NRGridComponent);
return NRGridComponent;
}());
(function (NRValueFormats) {
NRValueFormats[NRValueFormats["default"] = 0] = "default";
NRValueFormats[NRValueFormats["euro"] = 1] = "euro";
NRValueFormats[NRValueFormats["dolar"] = 2] = "dolar";
NRValueFormats[NRValueFormats["try"] = 3] = "try";
NRValueFormats[NRValueFormats["commaInt"] = 4] = "commaInt";
NRValueFormats[NRValueFormats["percent"] = 5] = "percent";
NRValueFormats[NRValueFormats["dateTime"] = 6] = "dateTime";
NRValueFormats[NRValueFormats["date"] = 7] = "date";
NRValueFormats[NRValueFormats["boolean"] = 8] = "boolean";
NRValueFormats[NRValueFormats["decimal"] = 9] = "decimal";
NRValueFormats[NRValueFormats["number"] = 10] = "number";
})(exports.NRValueFormats || (exports.NRValueFormats = {}));
var currencies = [{ "id": "SRD", "symbol": "$" },
{ "id": "ANG", "symbol": "ƒ" },
{ "id": "AOA", "symbol": "Kz" },
{ "id": "ARS", "symbol": "$" },
{ "id": "AUD", "symbol": "$" },
{ "id": "AWG", "symbol": "ƒ" },
{ "id": "BBD", "symbol": "$" },
{ "id": "BDT", "symbol": "৳" },
{ "id": "BGN", "symbol": "лв" },
{ "id": "BHD", "symbol": ".د.ب" },
{ "id": "ALL", "symbol": "L" },
{ "id": "BIF", "symbol": "Fr" },
{ "id": "BMD", "symbol": "$" },
{ "id": "BND", "symbol": "$" },
{ "id": "BOB", "symbol": "Bs." },
{ "id": "BRL", "symbol": "R$" },
{ "id": "BSD", "symbol": "$" },
{ "id": "BTN", "symbol": "Nu." },
{ "id": "BWP", "symbol": "P" },
{ "id": "BZD", "symbol": "$" },
{ "id": "CAD", "symbol": "$" },
{ "id": "CDF", "symbol": "Fr" },
{ "id": "CHF", "symbol": "Fr" },
{ "id": "CLP", "symbol": "$" },
{ "id": "CNY", "symbol": "¥" },
{ "id": "COP", "symbol": "$" },
{ "id": "CRC", "symbol": "₡" },
{ "id": "CUC", "symbol": "$" },
{ "id": "CUP", "symbol": "$" },
{ "id": "CVE", "symbol": "Esc" },
{ "id": "CZK", "symbol": "Kč" },
{ "id": "DJF", "symbol": "Fr" },
{ "id": "DKK", "symbol": "kr" },
{ "id": "DOP", "symbol": "$" },
{ "id": "DZD", "symbol": "د.ج" },
{ "id": "EGP", "symbol": "£" },
{ "id": "ERN", "symbol": "Nfk" },
{ "id": "ETB", "symbol": "Br" },
{ "id": "FJD", "symbol": "$" },
{ "id": "FKP", "symbol": "£" },
{ "id": "GBP", "symbol": "£" },
{ "id": "GEL", "symbol": "ლ" },
{ "id": "GIP", "symbol": "£" },
{ "id": "GMD", "symbol": "D" },
{ "id": "GNF", "symbol": "Fr" },
{ "id": "GTQ", "symbol": "Q" },
{ "id": "GYD", "symbol": "$" },
{ "id": "HKD", "symbol": "$" },
{ "id": "HNL", "symbol": "L" },
{ "id": "HRK", "symbol": "kn" },
{ "id": "HTG", "symbol": "G" },
{ "id": "HUF", "symbol": "Ft" },
{ "id": "IDR", "symbol": "Rp" },
{ "id": "ILS", "symbol": "₪" },
{ "id": "INR", "symbol": "₹" },
{ "id": "IQD", "symbol": "ع.د" },
{ "id": "ISK", "symbol": "kr" },
{ "id": "JMD", "symbol": "$" },
{ "id": "JOD", "symbol": "د.ا" },
{ "id": "JPY", "symbol": "¥" },
{ "id": "KES", "symbol": "Sh" },
{ "id": "KGS", "symbol": "с" },
{ "id": "KHR", "symbol": "៛" },
{ "id": "KMF", "symbol": "Fr" },
{ "id": "KRW", "symbol": "₩" },
{ "id": "KWD", "symbol": "د.ك" },
{ "id": "KYD", "symbol": "$" },
{ "id": "LAK", "symbol": "₭" },
{ "id": "LBP", "symbol": "ل.ل" },
{ "id": "LKR", "symbol": "Rs" },
{ "id": "LRD", "symbol": "$" },
{ "id": "LSL", "symbol": "L" },
{ "id": "LYD", "symbol": "ل.د" },
{ "id": "MAD", "symbol": "د.م." },
{ "id": "MDL", "symbol": "L" },
{ "id": "MGA", "symbol": "Ar" },
{ "id": "MKD", "symbol": "ден" },
{ "id": "MMK", "symbol": "Ks" },
{ "id": "MNT", "symbol": "₮" },
{ "id": "MOP", "symbol": "P" },
{ "id": "MRO", "symbol": "UM" },
{ "id": "MUR", "symbol": "₨" },
{ "id": "MVR", "symbol": ".ރ" },
{ "id": "MWK", "symbol": "MK" },
{ "id": "MXN", "symbol": "$" },
{ "id": "MYR", "symbol": "RM" },
{ "id": "NAD", "symbol": "$" },
{ "id": "NGN", "symbol": "₦" },
{ "id": "NIO", "symbol": "C$" },
{ "id": "NOK", "symbol": "kr" },
{ "id": "NPR", "symbol": "₨" },
{ "id": "NZD", "symbol": "$" },
{ "id": "OMR", "symbol": "ر.ع." },
{ "id": "PAB", "symbol": "B/." },
{ "id": "PEN", "symbol": "S/." },
{ "id": "PGK", "symbol": "K" },
{ "id": "PHP", "symbol": "₱" },
{ "id": "PKR", "symbol": "₨" },
{ "id": "PLN", "symbol": "zł" },
{ "id": "PYG", "symbol": "₲" },
{ "id": "QAR", "symbol": "ر.ق" },
{ "id": "RON", "symbol": "lei" },
{ "id": "RSD", "symbol": "дин." },
{ "id": "RUB", "symbol": "₽" },
{ "id": "RWF", "symbol": "Fr" },
{ "id": "SAR", "symbol": "ر.س" },
{ "id": "SBD", "symbol": "$" },
{ "id": "SCR", "symbol": "₨" },
{ "id": "SDG", "symbol": "ج.س." },
{ "id": "SEK", "symbol": "kr" },
{ "id": "SGD", "symbol": "$" },
{ "id": "SHP", "symbol": "£" },
{ "id": "SLL", "symbol": "Le" },
{ "id": "SOS", "symbol": "Sh" },
{ "id": "STD", "symbol": "Db" },
{ "id": "SYP", "symbol": "£" },
{ "id": "SZL", "symbol": "L" },
{ "id": "UYU", "symbol": "$" },
{ "id": "AFN", "symbol": "؋" },
{ "id": "AED", "symbol": "د.إ" },
{ "id": "EUR", "symbol": "€" },
{ "id": "THB", "symbol": "฿" },
{ "id": "TJS", "symbol": "ЅМ" },
{ "id": "TND", "symbol": "د.ت" },
{ "id": "TOP", "symbol": "T$" },
{ "id": "TRY", "symbol": "₺" },
{ "id": "TTD", "symbol": "$" },
{ "id": "TWD", "symbol": "$" },
{ "id": "TZS", "symbol": "Sh" },
{ "id": "UAH", "symbol": "₴" },
{ "id": "UGX", "symbol": "Sh" },
{ "id": "USD", "symbol": "$" },
{ "id": "VND", "symbol": "₫" },
{ "id": "VUV", "symbol": "Vt" },
{ "id": "WST", "symbol": "T" },
{ "id": "XAF", "symbol": "Fr" },
{ "id": "XCD", "symbol": "$" },
{ "id": "XOF", "symbol": "Fr" },
{ "id": "XPF", "symbol": "Fr" },
{ "id": "YER", "symbol": "﷼" },
{ "id": "ZAR", "symbol": "R" }];
var ValueFormatPipe = /** @class */ (function () {
function ValueFormatPipe() {
}
ValueFormatPipe.prototype.transform = function (value, type, currency) {
var valueTypeStr = '';
var baseSymbol;
if (typeof type == 'string') {
valueTypeStr = type;
}
if (currency) {
var found = lodash.find(currencies, function (x) {
return x && x.id && x.id == currency ? x : undefined;
});
if (found)
baseSymbol = found.symbol;
else
baseSymbol = currency;
}
else
baseSymbol = '';
var digits = 2;
if (valueTypeStr) {
switch (valueTypeStr) {
default:
case 'number':
type = exports.NRValueFormats.number;
break;
case 'bool':
type = exports.NRValueFormats.boolean;
break;
case 'dateTime':
type = exports.NRValueFormats.dateTime;
break;
case 'date':
type = exports.NRValueFormats.date;
break;
case 'decimal':
type = exports.NRValueFormats.decimal;
break;
case 'commaInt':
type = exports.NRValueFormats.commaInt;
break;
}
}
if (value == undefined && type != exports.NRValueFormats.boolean) {
return '';
}
switch (type) {
default:
case exports.NRValueFormats.default:
case exports.NRValueFormats.percent:
case exports.NRValueFormats.commaInt:
case exports.NRValueFormats.decimal:
case exports.NRValueFormats.number:
switch (type) {
case exports.NRValueFormats.percent:
baseSymbol = ' %';
break;
case exports.NRValueFormats.decimal:
digits = 3;
break;
case exports.NRValueFormats.number:
digits = 2;
break;
default:
case exports.NRValueFormats.commaInt:
digits = 0;
break;
}
return value
.toFixed(digits)
.replace('.', ',')
.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.') + ' ' + baseSymbol;
case exports.NRValueFormats.dateTime:
return format(value, 'dd/MM/yyyy HH:mm:ss');
case exports.NRValueFormats.date:
return format(value, 'dd/MM/yyyy');
case exports.NRValueFormats.boolean:
return value ? 'Yes' : 'No';
}
};
ValueFormatPipe = __decorate([
core.Pipe({ name: 'valueFormat' })
], ValueFormatPipe);
return ValueFormatPipe;
}());
var NrGridModule = /** @class */ (function () {
function NrGridModule() {
}
NrGridModule = __decorate([
core.NgModule({
declarations: [NRGridComponent, ValueFormatPipe],
imports: [
ngBootstrap.NgbModule,
common.CommonModule,
forms.FormsModule,
nrSelect.NrSelectModule
],
exports: [NRGridComponent, ValueFormatPipe]
})
], NrGridModule);
return NrGridModule;
}());
var NRGridOptions = /** @class */ (function () {
function NRGridOptions() {
}
return NRGridOptions;
}());
var NRDataSource = /** @class */ (function () {
function NRDataSource() {
}
return NRDataSource;
}());
var NRCellLink = /** @class */ (function () {
function NRCellLink() {
}
return NRCellLink;
}());
var NRGridColumn = /** @class */ (function () {
function NRGridColumn(init) {
Object.assign(this, init);
}
return NRGridColumn;
}());
var NRRowClickAction = /** @class */ (function () {
function NRRowClickAction() {
}
return NRRowClickAction;
}());
exports.NRCellLink = NRCellLink;
exports.NRDataSource = NRDataSource;
exports.NRGridColumn = NRGridColumn;
exports.NRGridComponent = NRGridComponent;
exports.NRGridOptions = NRGridOptions;
exports.NRRowClickAction = NRRowClickAction;
exports.NrGridModule = NrGridModule;
exports.NrGridService = NrGridService;
exports.ValueFormatPipe = ValueFormatPipe;
exports.currencies = currencies;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=nr-grid.umd.js.map