<template>
<div id="app">
<ejs-button :isPrimary="true" v-on:click.native="btnClick"
>Get the columns</ejs-button
>
<ejs-grid
ref="grid"
:dataSource="data"
:allowPaging="true"
:allowFiltering="true"
:filterSettings="filterSettings"
>
<e-columns>
<e-column
. . .
</e-columns>
</ejs-grid>
</div>
</template>
<script>
export default {
name: "App",
data() {
return {
data: orderData,
filterSettings: { type: "Menu" },
filter: {
type: "CheckBox",
},
};
},
methods: {
btnClick: function () {
var grid = this.$refs.grid.ej2Instances;
// here we can get the columns of the Grid and you can perform your operation here
console.log(grid.getColumns());
},
},
provide: {
grid: [Page, Filter],
},
};
</script> |
<ejs-grid
ref="grid"
:dataSource="data"
:allowPaging="true"
:enablePersistence="true"
:allowFiltering="true"
:filterSettings="filterSettings"
> |
//get the Grid model.
let value = window.localStorage.getItem('gridGrid'); //"gridGrid" is component name + component id.
let model = JSON.parse(model);
actionHandler: function (){
this.$refs.grid.ej2Instances.query.addParams('$filter', 'EmployeeID eq 1');
}
<template>
<div id="app">
<ejs-button v-on:click.native="btnClick" :isPrimary="true"
>Store Filter1</ejs-button
>
<ejs-button v-on:click.native="btnClick1" :isPrimary="true"
>Store Filter2</ejs-button
>
<ejs-button cssClass="e-success" v-on:click.native="btnClick2"
>Apply Filter1</ejs-button
>
<ejs-button cssClass="e-success" v-on:click.native="btnClick3"
>Apply Filter2</ejs-button
>
<ejs-grid
ref="grid"
:dataSource="data"
:allowPaging="true"
:allowFiltering="true"
:filterSettings="filterSettings"
>
. . .
</e-columns>
</ejs-grid>
</div>
</template>
<script>
import Vue from "vue";
import { GridPlugin, Page, Filter } from "@syncfusion/ej2-vue-grids";
import { orderData } from "./dataSource";
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
Vue.use(GridPlugin);
Vue.use(ButtonPlugin);
export default {
name: "App",
data() {
return {
data: orderData.slice(0, 50),
filterSettings: { type: "Menu" },
filter: {
type: "CheckBox",
},
};
},
methods: {
btnClick: function () {
// here you can store the filterSettings in the local storage
var grid = this.$refs.grid.ej2Instances;
var model = JSON.parse(grid.getPersistData()).filterSettings;
window.localStorage.setItem("gridGrid1", JSON.stringify(model));
},
btnClick1: function () {
var grid = this.$refs.grid.ej2Instances;
var model = JSON.parse(grid.getPersistData()).filterSettings;
window.localStorage.setItem("gridGrid2", JSON.stringify(model));
},
btnClick2: function () {
// here you can retrieve the filterSettings in the local storage and apply to the Grid
var grid = this.$refs.grid.ej2Instances;
grid.clearFiltering();
var model = window.localStorage.getItem("gridGrid1");
grid.setProperties({ filterSettings: JSON.parse(model) });
},
btnClick3: function () {
var grid = this.$refs.grid.ej2Instances;
grid.clearFiltering();
var model = window.localStorage.getItem("gridGrid2");
grid.setProperties({ filterSettings: JSON.parse(model) });
},
},
provide: {
grid: [Page, Filter],
},
};
</script>
<style>
@import "https://cdn.syncfusion.com/ej2/material.css";
</style> |
<ejs-grid :id="pgridtable" :ref="pgridtable" :dataSource="data" height="100%" :allowResizing='true'
:toolbarTemplate='toolbar' :allowSorting='true' :allowFiltering='true' :allowPaging="true"
:filterSettings='filterOptions' :pageSettings="pageSettings" :showColumnChooser='true'
:allowExcelExport='true' :allowPdfExport='true' :recordClick="recordClick" :recordDoubleClick="recordDoubleClick"
:actionBegin="actionBegin" :allowReordering='true' :dataBound="loadLocalViewsAvailable" >
<e-columns>
<e-column v-for="coldefine in columns"
:key="coldefine.field"
:field="coldefine.field.toString()"
:filter="filterMapper(coldefine.filter)"
:headerText='msg(coldefine.headerText)'
:customAttributes="customMapper(coldefine.customAttributes)"
:textAlign="coldefine.textAlign"
width=90
:visible="coldefine.visible === 'false' ? false : (coldefine.visible === 'true' ? true : null)"
:hideAtMedia="coldefine.hideAtMedia"
:disableHtmlEncode="false"
:type="typeof coldefine.colType !== 'undefined' && (coldefine.colType == 3 || coldefine.colType == 4) ? 'date' : undefined"
:format="getFormatByColType(coldefine.colType)"
/>
</e-columns>
</ejs-grid>
loadLocalViewsAvailable() {
if(this.availableLocalViewFull.length > 0) return;
let strArrayLocalView = window.localStorage.getItem(this.localViewKey);
if(strArrayLocalView) {
let $this = this;
let lArrSaver = JSON.parse(strArrayLocalView);
this.availableLocalViewFull = lArrSaver;
let gridInstance = this.$refs[this.pgridtable].ej2Instances;
//-- 1 - filterToApply
//-- cleanFilters - Api function
//-- Apply filters
//-- Apply default
this.availableLocalViewFull.forEach((elm) => {
if(elm.view.fav) {
$this.selectedLocalView = elm.view;
//setTimeout(() => {
//-- Hide
$this.$refs[$this.pgridtable].hideColumns(elm.hiddenCol, "field");
//-- Order
let arrCol = $this.$refs[$this.pgridtable].getColumns().map(f => f.index);
if(elm.orderCol.length == arrCol.length) {
for(let i = 0; i < elm.orderCol.length; i++) {
if(elm.orderCol[i] !== arrCol[i]) {
let indx = arrCol.findIndex(v => v === elm.orderCol[i]);
$this.$refs[$this.pgridtable].reorderColumnByIndex(indx, i);
arrCol = $this.$refs[$this.pgridtable].getColumns().map(f => f.index);
}
}
}
//-- Refresh UI
$this.$refs[$this.pgridtable].refreshColumns();
//-- Filter application
gridInstance.clearFiltering();
if(typeof elm.dateFilterValues !== 'undefined') {
$this.dateValue = elm.dateFilterValues;
}
if(typeof elm.gridProperties !== 'undefined') {
gridInstance.setProperties({filterSettings: elm.gridProperties});
}
//}, 1000);
}
});
}
},
applyView() {
let allCol = this.$refs[this.pgridtable].getColumns().map((c) => c.field);
this.$refs[this.pgridtable].showColumns(allCol, "field");
let arrCol = this.$refs[this.pgridtable].getColumns().map(f => f.index);
//-- Default BDD order 0 -> length
let orderCol = [...Array(arrCol.length).keys()];
//-- ClearFilter
let gridInstance = this.$refs[this.pgridtable].ej2Instances;
gridInstance.clearFiltering();
if(this.selectedLocalView) {
//-- Hide
this.$refs[this.pgridtable].hideColumns(this.availableLocalViewFull[this.selectedLocalView.id].hiddenCol, "field");
//-- Reorder
orderCol = this.availableLocalViewFull[this.selectedLocalView.id].orderCol;
//-- Apply
if(typeof this.availableLocalViewFull[this.selectedLocalView.id].gridProperties !== 'undefined') {
gridInstance.setProperties({ filterSettings: this.availableLocalViewFull[this.selectedLocalView.id].gridProperties });
}
}
if(orderCol.length == arrCol.length) {
for(let i = 0; i < orderCol.length; i++) {
if(orderCol[i] !== arrCol[i]) {
let indx = arrCol.findIndex(v => v === orderCol[i]);
this.$refs[this.pgridtable].reorderColumnByIndex(indx, i);
arrCol = this.$refs[this.pgridtable].getColumns().map(f => f.index);
}
}
}
},