zoukankan      html  css  js  c++  java
  • Vue之sortable实现排序功能

    1.vue代码

    <template>
          <el-table @selection-change="handleSelectionChange" @sort-change="sortChange" v-loading="loading" id = "TableColumnID" element-loading-text="加载中..." :data="listData.List" highlight-current-row style=" 100%;">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column width="80" prop="UserName" label="登录名" :show-overflow-tooltip="true" sortable="custom"></el-table-column>
            <el-table-column width="80" prop="byName" label="姓名" :show-overflow-tooltip="true" sortable="custom"></el-table-column>
            <el-table-column :formatter="roleType" prop="Role" label="用户权限" :show-overflow-tooltip="true" sortable="custom" width="150"></el-table-column>
            <el-table-column prop="LastActivityTime" label="更新时间" sortable="custom" width="200"></el-table-column>
            <el-table-column prop="CreateTime" label="创建时间" sortable="custom" width="200"></el-table-column>
            <el-table-column fixed="right" label="操作" align="center">
              <template slot-scope="scope">
                <el-button type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
                <el-button type="danger" size="small" @click="handleDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>

    2.sort-change事件分析

    如果需要后端实现排序功能,需要将sortable设置为custom,同时在 Table 上监听sort-change事件,在事件回调中可以获取当前排序的字段名和排序顺序,从而向接口请求排序后的表格数据。

    sort-change方法自带三个参数,分别代表意义是:
    column:当前列
    prop:当前列需要排序的数据
    order:排序的规则(升序、降序和默认[默认就是没排序])

    3.JS代码:

     data() {
        return {
          loading: false,
          listData: [],
          addVisible: false,
          currentObj: { U: {}, UAccount: {} },
          queryData: {
            UserName: "",
            CustomerCode: "",
            CustomerName: "",
            role: 0,
            p_Role: "",
            prop : "",
            order : "",
            currentPage: 1,
            pageSize: 10
          },
          EUserP_Role: [],
          p_Role: {},
          ids: []
        };
      },
     methods: {
        sortChange(column,prop,order){
          if(column.prop == null || column.order == null){
            this.queryData.prop = "";
            this.queryData.order = "";
          }else{
             this.queryData.prop = column.prop;
             this.queryData.order = column.order;
          }
          this.getList();
        },
        getList() {
          this.loading = true;
          this.$API.User.List(this.queryData).then(res => {
            this.loading = false;
            this.listData = res;
            this.currentPage = 1;
            this.prop = column.prop;
            this.order = column.order;
          });
        }

    参考---https://blog.csdn.net/nxw_tsp/article/details/86096914

  • 相关阅读:
    [Golang学习笔记] 06 程序实体3 类型断言和类型转换
    [Golang学习笔记] 05 程序实体2 作用域访问权限和变量重声明
    [Golang学习笔记] 04 程序实体1 变量声明
    [Golang学习笔记] 03 库源码文件
    virgo-tomcat-server的生产环境线上配置与管理
    virgo-tomcat-server最大并发连接数的修改
    linux系统下kvm虚拟机的安装
    关于virgo-tomcat-server-3.6.0.RELEASE配置文件修改说明
    关于在Linux下apache-maven的安装
    H3C系列之三层交换机文件管理
  • 原文地址:https://www.cnblogs.com/pwindy/p/14838236.html
Copyright © 2011-2022 走看看