el-table排序以及echarts数据视图优化

一、el-table排序
1、java

 @RequestParam(value="prop", required=false) String prop,
 @RequestParam(value="sort", required=false) String sort,


/*排序*/
		String sortStr="";
		if ((prop!=""&&prop!=null)&&(sort!=""&&sort!=null)){
			sortStr="order by"+" "+prop+" "+sort;
		}else {
			sortStr="order by id DESC";
		}

sql:	"${sortStr} limit #{currPosition}, #{pageSize}",

2、vue

 <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="载入中"
      border
      fit
      stripe
      highlight-current-row
      :height="tableHeight"
      @sort-change="sortChange"
    >
     

      <el-table-column label="手续费" width="180px" align="center"  sortable="custom" prop="fee">
        <template slot-scope="scope">
          <span>{{ scope.row.fee }}</span>
        </template>
      </el-table-column>
  
    </el-table>

    <Pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

info: {
        prop:"",
        sort:"",
      },

    /*排序*/
    sortChange:function(column,prop,order){
      /*      console.log(column)
            console.log(prop)
             console.log(order)*/
      if (column.order=="descending"){
        this.info.sort="DESC"
        this.info.prop=column.prop
      }else if (column.order=="ascending") {
        this.info.sort="ASC"
        this.info.prop=column.prop
      }
      this.getList()

    },

    getList() {
      var url = this.HOST + '/xxx/xxxx?page=' + this.listQuery.page + '&rows=' + this.listQuery.limit
      var qs = require('qs')
      var instance = this.$axios.create({
        headers: { 'content-type': 'application/x-www-form-urlencoded' }
      })
      instance.post(url, qs.stringify(this.info))
        .then((response) => {
          const res = response.data
          if (res.needReLogin === 1) {
            this.$store.dispatch('LogOut').then(() => {
              location.reload()
            })
          }
          this.listLoading = false
          this.list = res.rows
          this.total = res.total

        })
    },


二、echarts数据视图优化
转载于:添加链接描述


optionToContent: function (opt) {
    let axisData = opt.xAxis[0].data; //坐标数据
    let series = opt.series; //折线图数据
    let tdHeads = '<td  style="padding: 0 10px">时间</td>'; //表头
    let tdBodys = ''; //数据
    series.forEach(function (item) {
        //组装表头
        tdHeads += `<td style="padding: 0 10px">${item.name}</td>`;
    });
    let table = `<table border="1" style="margin-left:20px;border-collapse:collapse;font-size:14px;text-align:center"><tbody><tr>${tdHeads} </tr>`;
    for (let i = 0, l = axisData.length; i < l; i++) {
        for (let j = 0; j < series.length; j++) {
            //组装表数据
            tdBodys += `<td>${ series[j].data[i]}</td>`;
        }
        table += `<tr><td style="padding: 0 10px">${axisData[i]}</td>${tdBodys}</tr>`;
        tdBodys = '';
    }
    table += '</tbody></table>';
    return table;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值