找回密码
 立即注册

QQ登录

只需一步,快速开始

rlj

注册会员

3

主题

7

帖子

20

积分

注册会员

积分
20
  • 101

    金币

  • 3

    主题

  • 7

    帖子

最新发帖
rlj
注册会员   /  发表于:2023-9-4 17:33  /   查看:1044  /  回复:1
1金币
页面代码


<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>


最佳答案

查看完整内容

看到这里你是又new了一个filter出来,这样就不是拿到的默认显示的filter,设置和获取都是不对的,正确的应该是初始化的时候,获取到这个filter标签对应的 filter对象。进行后续操作 我把在线示例中的demo代码稍微改了一下,参考下面的代码,复制到原来的vue示例中就可以验证了 https://www.grapecity.com/wijmo/demos/Grid/FilteringSearching/Excel-likeFilter/Overview/vue 将下面的代码全部复制到app.vue中运行,点击按 ...

1 个回复

倒序浏览
最佳答案
最佳答案
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2023-9-4 17:33:54
来自 2#
看到这里你是又new了一个filter出来,这样就不是拿到的默认显示的filter,设置和获取都是不对的,正确的应该是初始化的时候,获取到这个filter标签对应的 filter对象。进行后续操作

我把在线示例中的demo代码稍微改了一下,参考下面的代码,复制到原来的vue示例中就可以验证了

https://www.grapecity.com/wijmo/ ... Filter/Overview/vue
将下面的代码全部复制到app.vue中运行,点击按钮即可




  1. <template>
  2.    
  3.     <div class="container-fluid">
  4.         <!-- the grid -->
  5.         <wj-flex-grid :itemsSource="data" :initialized="initGrid">
  6.             <wj-flex-grid-filter :initialized="initialized"/>
  7.         </wj-flex-grid>
  8.         <button @click="searchdata">设置过滤结果</button>
  9.     </div>
  10. </template>

  11. <script>
  12. import "@grapecity/wijmo.styles/wijmo.css";
  13. import "bootstrap.css";
  14. import Vue from "vue";
  15. import "@grapecity/wijmo.vue2.grid";
  16. import * as wjcGrid from "@grapecity/wijmo.grid";
  17. import "@grapecity/wijmo.vue2.grid.filter";
  18. import * as wjcCore from "@grapecity/wijmo";
  19. import  {FlexGridFilter, FilterType} from '@grapecity/wijmo.grid.filter';

  20. let App = Vue.extend({
  21.     name: "app",
  22.     data: function() {
  23.         return {
  24.             data: this.getData(),
  25.             grid:null,
  26.             filter:null
  27.         };
  28.     },
  29.     methods: {
  30.         getData: function() {
  31.             // create some random data
  32.             let countries = "US,Germany,UK,Japan,Italy,Greece".split(","),
  33.                 data = [];
  34.             for (let i = 0; i < 200; i++) {
  35.                 data.push({
  36.                     id: i,
  37.                     country: countries[i % countries.length],
  38.                     downloads: Math.round(Math.random() * 20000),
  39.                     sales: Math.random() * 10000,
  40.                     expenses: Math.random() * 5000
  41.                 });
  42.             }
  43.             return data;
  44.         },
  45.         searchdata(){
  46.             
  47.             var col = this.grid.columns.getColumn(1);
  48.                   var cf = this.filter.getColumnFilter(col);
  49.                   cf.valueFilter.showValues={ Japan: true };
  50.               this.filter.apply();
  51.         },
  52.         initGrid(grid){
  53.             this.grid=grid;
  54.         },
  55.         initialized: function(filter) {
  56.             this.filter = filter;

  57.         }
  58.     }
  59. });

  60. new Vue({ render: h => h(App) }).$mount("#app");
  61. </script>

  62. <style>
  63. .wj-flexgrid {
  64.     max-height: 250px;
  65.     margin: 10px 0;
  66. }
  67. body {
  68.     margin-bottom: 20px;
  69. }

  70. /* show images on filtered columns */
  71. .custom-icons .wj-glyph-filter {
  72.     background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAABKUlEQVQ4ja2QP0vDQBiHf/cndzQhJKGGK6HQHFnsII4h4GfQqas4+zGcXDs5dNRPYj+EoFt316CDPZcrhNY0Mb0HnuV43+e4AxxhjKF1XU+bZ3MANwOdH9wghHgAYIZod/8OKqWWRVHc9VEptWwNJklyBeCbUrrRWs8Wi4U4ptZ6RindAPiyu4cEQXALYMsYM57nHZUxZgBs7U47vu/3/ks72wlhjL10xRhjz31iAICqqkac83VbjHO+rqpq1DsIAGEYjoUQH1JK01QI8R6G4fhfsR15nk+SJLlomuf5ZFAMANI0fcTec+3ZacEoilZRFK2cBQGcW90EpZT3ToJKqWtCyCcA43ne28lBAMiy7ExK+UQI+XES3BHH8aWU8tVZ0ELKspx2jznkF5WQhrjMdSwdAAAAAElFTkSuQmCC");
  73.     background-repeat: no-repeat;
  74.     background-position: bottom right;
  75.     margin-top: 2px;
  76.     width: 20px;
  77.     height: 20px;
  78.     border: none;
  79. }
  80. .custom-icons .wj-glyph-filter:after {
  81.     display: none;
  82. }
  83. /* make active filter images 25% larger */
  84. .custom-icons .wj-filter-on .wj-glyph-filter {
  85.     transform: scale(1.25);
  86. }

  87. /* change the color of the filter glyphs */
  88. .custom-colors .wj-glyph-filter {
  89.     color: red;
  90.     font-size: 125%;
  91. }
  92. </style>
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部