autocomplete options added to smart table
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
a1970c6fc8
commit
11f24372e5
|
@ -2,6 +2,7 @@
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<div class="actions-left">
|
<div class="actions-left">
|
||||||
<vn-button icon="view_column"
|
<vn-button icon="view_column"
|
||||||
|
ng-if="$ctrl.viewConfigId"
|
||||||
ng-click="smartTableColumns.show($event)"
|
ng-click="smartTableColumns.show($event)"
|
||||||
vn-tooltip="Shown columns">
|
vn-tooltip="Shown columns">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import Component from '../../lib/component';
|
||||||
import {buildFilter} from 'vn-loopback/util/filter';
|
import {buildFilter} from 'vn-loopback/util/filter';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
import angular from 'angular';
|
import angular from 'angular';
|
||||||
|
import {camelToKebab} from '../../lib/string';
|
||||||
|
|
||||||
export default class SmartTable extends Component {
|
export default class SmartTable extends Component {
|
||||||
constructor($element, $, $transclude) {
|
constructor($element, $, $transclude) {
|
||||||
|
@ -199,13 +200,37 @@ export default class SmartTable extends Component {
|
||||||
const field = column.getAttribute('field');
|
const field = column.getAttribute('field');
|
||||||
const cell = document.createElement('td');
|
const cell = document.createElement('td');
|
||||||
if (field) {
|
if (field) {
|
||||||
const input = this.$compile(`
|
let input;
|
||||||
|
let options;
|
||||||
|
const columnOptions = this.options && this.options.columns;
|
||||||
|
|
||||||
|
if (columnOptions)
|
||||||
|
options = columnOptions.find(column => column.field == field);
|
||||||
|
|
||||||
|
if (options && options.autocomplete) {
|
||||||
|
let props = ``;
|
||||||
|
|
||||||
|
const autocomplete = options.autocomplete;
|
||||||
|
for (const prop in autocomplete)
|
||||||
|
props += `${camelToKebab(prop)}="${autocomplete[prop]}"\n`;
|
||||||
|
|
||||||
|
input = this.$compile(`
|
||||||
|
<vn-autocomplete
|
||||||
|
name="${field}"
|
||||||
|
ng-model="searchProps['${field}']"
|
||||||
|
${props}
|
||||||
|
on-change="$ctrl.searchByColumn('${field}')"
|
||||||
|
clear-disabled="true"
|
||||||
|
/>`)(this.$);
|
||||||
|
} else {
|
||||||
|
input = this.$compile(`
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
name="${field}"
|
name="${field}"
|
||||||
ng-model="searchProps['${field}']"
|
ng-model="searchProps['${field}']"
|
||||||
ng-keydown="$ctrl.searchByColumn($event, this, '${field}')"
|
ng-keydown="$ctrl.searchWithEvent($event, '${field}')"
|
||||||
clear-disabled="true"
|
clear-disabled="true"
|
||||||
/>`)(this.$);
|
/>`)(this.$);
|
||||||
|
}
|
||||||
cell.appendChild(input[0]);
|
cell.appendChild(input[0]);
|
||||||
}
|
}
|
||||||
searchRow.appendChild(cell);
|
searchRow.appendChild(cell);
|
||||||
|
@ -214,10 +239,14 @@ export default class SmartTable extends Component {
|
||||||
tbody.prepend(searchRow);
|
tbody.prepend(searchRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
searchByColumn($event, scope, field) {
|
searchWithEvent($event, field) {
|
||||||
if ($event.key != 'Enter') return;
|
if ($event.key != 'Enter') return;
|
||||||
|
|
||||||
const searchCriteria = scope.searchProps[field];
|
this.searchByColumn(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
searchByColumn(field) {
|
||||||
|
const searchCriteria = this.$.searchProps[field];
|
||||||
const emptySearch = searchCriteria == '' || null;
|
const emptySearch = searchCriteria == '' || null;
|
||||||
|
|
||||||
const filters = this.filterSanitizer(field);
|
const filters = this.filterSanitizer(field);
|
||||||
|
@ -226,7 +255,7 @@ export default class SmartTable extends Component {
|
||||||
this.model.userFilter = filters.userFilter;
|
this.model.userFilter = filters.userFilter;
|
||||||
|
|
||||||
if (!emptySearch)
|
if (!emptySearch)
|
||||||
this.addFilter(field, scope.searchProps[field]);
|
this.addFilter(field, this.$.searchProps[field]);
|
||||||
else this.model.refresh();
|
else this.model.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +373,7 @@ ngModule.vnComponent('smartTable', {
|
||||||
viewConfigId: '@?',
|
viewConfigId: '@?',
|
||||||
autoSave: '<?',
|
autoSave: '<?',
|
||||||
exprBuilder: '&?',
|
exprBuilder: '&?',
|
||||||
defaultNewData: '&?'
|
defaultNewData: '&?',
|
||||||
|
options: '<?'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<smart-table
|
<smart-table
|
||||||
model="model"
|
model="model"
|
||||||
view-config-id="ticketIndex"
|
view-config-id="ticketIndex"
|
||||||
|
options="$ctrl.smartTableOptions"
|
||||||
auto-save="true"
|
auto-save="true"
|
||||||
expr-builder="$ctrl.exprBuilder(param, value)"
|
expr-builder="$ctrl.exprBuilder(param, value)"
|
||||||
default-new-data="$ctrl.defaultNewData()">
|
default-new-data="$ctrl.defaultNewData()">
|
||||||
|
@ -20,7 +21,6 @@
|
||||||
ng-click="$ctrl.test()"
|
ng-click="$ctrl.test()"
|
||||||
vn-tooltip="Info">
|
vn-tooltip="Info">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
|
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<vn-button icon="info"
|
<vn-button icon="info"
|
||||||
ng-click="$ctrl.test()"
|
ng-click="$ctrl.test()"
|
||||||
|
|
|
@ -7,6 +7,44 @@ export default class Controller extends Section {
|
||||||
constructor($element, $, vnReport) {
|
constructor($element, $, vnReport) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
this.vnReport = vnReport;
|
this.vnReport = vnReport;
|
||||||
|
this.smartTableOptions = {
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
field: 'salesPersonFk',
|
||||||
|
autocomplete: {
|
||||||
|
url: 'Workers/activeWithInheritedRole',
|
||||||
|
where: `{role: 'salesPerson'}`,
|
||||||
|
searchFunction: '{firstName: $search}',
|
||||||
|
showField: 'nickname',
|
||||||
|
valueField: 'id',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'provinceFk',
|
||||||
|
autocomplete: {
|
||||||
|
url: 'Provinces',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'stateFk',
|
||||||
|
autocomplete: {
|
||||||
|
url: 'States',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'zoneFk',
|
||||||
|
autocomplete: {
|
||||||
|
url: 'Zones',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'warehouseFk',
|
||||||
|
autocomplete: {
|
||||||
|
url: 'Warehouses',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
setDelivered() {
|
setDelivered() {
|
||||||
|
|
Loading…
Reference in New Issue