页面代码
<template>
<div class="componentContainer" >
<button @click="searchdata">查询</button>
<div class="spreadContainer" >
<wj-flex-grid :items-source="data" id="theGrid" :initialized="initGrid">
<wj-flex-grid-filter :filter-columns="filtercolumns" :filter-applied="FilterApplied">
</wj-flex-grid-filter>
</wj-flex-grid>
<!--<gc-spread-sheets
:hostClass='"spreadHost"'>
</gc-spread-sheets>-->
</div>
</div>
</template>
<script>
import '@grapecity/wijmo.styles/wijmo.css'
import * as wjcCore from '@grapecity/wijmo'
import * as wjcGrid from '@grapecity/wijmo.grid'
import '@grapecity/wijmo.vue2.grid'
import '@grapecity/wijmo.vue2.input'
import '@grapecity/wijmo.cultures/wijmo.culture.zh.js'
import "@grapecity/wijmo.vue2.grid.filter";
import {FlexGridFilter, FilterType} from '@grapecity/wijmo.grid.filter';
//import '@assets/wijmo.grid.min.js';
export default {
name: 'sample-wijmo',
data(){
return {
data: null,
filtercolumns: ['行号','country'],
grid: null
}
},
// watch filter and update CollectionView when it changes
created: function () {
},
// connect group panel and grid
mounted: function () {
},
methods: {
initGrid: function (grid) {
//this.getData()
this.grid = grid
},
FilterApplied(s){
console.log('s',s)
this.filtercolumns.forEach((item,index) => {
let valueFilter = s.getColumnFilter(item, true).valueFilter;
valueFilter.uniqueValues = null;
// 筛选框选中的值
let val = valueFilter._values
console.log('val',val)
if(val != undefined){
localStorage.setItem(item,JSON.stringify(val))
}
})
},
searchdata(){
this.data = this.getData()
this.$nextTick(() => {
let filter = new FlexGridFilter(this.grid);
filter.defaultFilterType = FilterType.Value;
//console.log(filter)
this.filtercolumns.forEach((item,index) => {
var sval = localStorage.getItem(item)
if(sval && sval != undefined){
var col = this.grid.columns.getColumn(item),
cf = filter.getColumnFilter(col);
cf.valueFilter.showValues = JSON.parse(sval)
console.log('cf',cf)
}
})
// filter.filterApplied.addHandler(function (s1, e1) {
// //console.log(s1)
// filtercol.forEach((item,index) => {
// let valueFilter = s1.getColumnFilter(item, true).valueFilter;
// valueFilter.uniqueValues = null;
// // 筛选框选中的值
// let val = valueFilter._values
// console.log('val',val)
// if(val != undefined){
// localStorage.setItem(item,JSON.stringify(val))
// }
// })
// });
})
},
getData() {
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
data = [];
for (var i = 0; i < 100; i++) {
data.push({
'行号': i,
country: countries[i % countries.length],
date: new Date(2014, i % 12, i % 28),
amount: i+1 + '',
active: i % 4 == 0
});
}
return data;
}
},
}
</script>
<style scoped>
.componentContainer {
width: 80%;
position: absolute;
padding: 10px;
left: 50%;
top: 0;
bottom: 20px;
right: 0;
transform: translateX(-50%);
}
.spreadContainer{
position: absolute;
height: 400px;
left: 0px;
right: 30px;
top: 80px;
bottom: 10px;
padding: 10px;
box-shadow: 0 0 20px grey;
overflow: hidden;
}
.spreadHost{
width: 100%;
height: 100%;
}
.wj-flexgrid{
height: 100%;
}
</style>
|