Vxe UI vue vxe-table grid 如何滚动、定位到指定行或列

news2024/10/21 15:09:48

Vxe UI vue vxe-table vxe-grid 在表格中有时候需要对数据会列进行操作。可以会定位到某一行或某一列,vxe-table 中提供了丰富的函数式 API,可以轻松对行与列进行各种的灵活的操作。

定位到指定行与列

通过调用 scrollColumn(columnOrField) 方法,参数就是当前列的字段名
通过调用 scrollRow(row, column?: columnOrField) 方法,参数就是当前行对象
第二个参数是可选的,支持同时定位到指定列

在这里插入图片描述

调用该方法之后会始终显示在表格的可视区之内。

<template>
  <div>
    <div>
      <vxe-button @click="scrollToCol('attr1')">定位 Attr1 列</vxe-button>
      <vxe-button @click="scrollToCol('attr4')">定位 Attr4 列</vxe-button>
      <vxe-button @click="scrollToCol('attr8')">定位 Attr8 列</vxe-button>
    </div>
    <div>
      <vxe-button @click="scrollToRow(gridOptions.data[3])">定位第4行</vxe-button>
      <vxe-button @click="scrollToRow(gridOptions.data[9])">定位第10行</vxe-button>
      <vxe-button @click="scrollToRow(gridOptions.data[15])">定位第16行</vxe-button>
    </div>
    <vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
const gridRef = ref()
const gridOptions = reactive({
  border: true,
  showOverflow: true,
  height: 400,
  columns: [
    { type: 'seq', width: 70, fixed: 'left' },
    { field: 'name', title: 'Name', fixed: 'left', width: 200 },
    { field: 'role', title: 'Role', width: 300 },
    { field: 'attr1', title: 'Attr1', width: 400 },
    { field: 'attr2', title: 'Attr2', width: 300 },
    { field: 'attr3', title: 'Attr3', width: 700 },
    { field: 'attr4', title: 'Attr4', width: 600 },
    { field: 'attr5', title: 'Attr5', width: 500 },
    { field: 'attr6', title: 'Attr6', width: 400 },
    { field: 'attr7', title: 'Attr7', width: 200 },
    { field: 'attr8', title: 'Attr8', width: 500 },
    { field: 'attr9', title: 'Attr9', width: 600 },
    { field: 'attr10', title: 'Attr10', width: 500 },
    { field: 'age', title: 'Age', width: 200 },
    { field: 'sex', title: 'Sex', fixed: 'right', width: 100 },
    { field: 'address', title: 'Address', fixed: 'right', width: 140 }
  ],
  data: [
    { id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 23, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10005, name: 'Test5', role: 'Develop', sex: 'Women', age: 30, address: 'Shanghai', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10006, name: 'Test6', role: 'Designer', sex: 'Women', age: 21, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10007, name: 'Test7', role: 'Test', sex: 'Man', age: 29, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10008, name: 'Test8', role: 'Develop', sex: 'Man', age: 35, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10009, name: 'Test9', role: 'Test', sex: 'Man', age: 26, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10010, name: 'Test10', role: 'Develop', sex: 'Man', age: 38, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10011, name: 'Test11', role: 'Test', sex: 'Women', age: 29, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10012, name: 'Test12', role: 'Develop', sex: 'Man', age: 27, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10013, name: 'Test13', role: 'Test', sex: 'Women', age: 24, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10014, name: 'Test14', role: 'Develop', sex: 'Man', age: 34, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10015, name: 'Test15', role: 'Test', sex: 'Man', age: 21, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10016, name: 'Test16', role: 'Develop', sex: 'Women', age: 20, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10017, name: 'Test17', role: 'Test', sex: 'Man', age: 31, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10018, name: 'Test18', role: 'Develop', sex: 'Women', age: 32, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10019, name: 'Test19', role: 'Test', sex: 'Man', age: 37, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' },
    { id: 10020, name: 'Test20', role: 'Develop', sex: 'Man', age: 41, address: 'test abc', attr1: '', attr2: '', attr3: '', attr4: '', attr5: '', attr6: '', attr7: '', attr8: '', attr9: '', attr10: '' }
  ]
})
const scrollToCol = (field) => {
  const $grid = gridRef.value
  if ($grid) {
    $grid.scrollToColumn(field)
  }
}
const scrollToRow = (row) => {
  const $grid = gridRef.value
  if ($grid) {
    $grid.scrollToRow(row)
  }
}

</script>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2220107.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【Python】图形用户界面

在Python中&#xff0c;开发图形用户界面&#xff08;GUI&#xff09;的工具包有许多种&#xff0c;常用的包括&#xff1a; Tkinter&#xff1a;Python的标准GUI库&#xff0c;作为Python内置的一部分&#xff0c;简单易用&#xff0c;适用于轻量级应用。PyQt/PySide&#xf…

探索面向对象编程的核心:类、对象与封装

探索面向对象编程的核心&#xff1a;类、对象与封装 在学习Java编程时&#xff0c;面向对象编程&#xff08;OOP&#xff09;是一个非常重要的核心概念。今天我们将深入探讨其中最基本、但却非常重要的组成部分&#xff1a;类和对象&#xff0c;以及它们是如何通过封装来实现数…

全网免费的文献调研方法以及获取外网最新论文、代码和翻译pdf论文的方法(适用于硕士、博士、科研)

1. 文献调研 学术搜索引擎(十分推荐前三个&#xff0c;超有用)&#xff1a;使用 Google Scholar(https://scholar.google.com/)(https://scholar.google.com.tw/)(巨人学术搜索‬‬)、&#xff08;三个都可以&#xff0c;镜像网站&#xff09; arXiv(https://arxiv.org/)、&am…

企业架构系列(21)ArchiMate建模ADM阶段A:架构愿景

从本篇开始&#xff0c;将通过6篇文章逐一介绍如何使用 ArchiMate 的特定视角来创建与 TOGAF 架构开发方法相关的图形化模型或图表&#xff08;即&#xff0c;ADM中的图形制品&#xff0c;Graphical Artifacts&#xff09;。这些制品让利益相关者以可视化的方式来理解架构内容&…

vscode中每个打开的文件都显示在一个单独的标签页中

版本&#xff1a;1.94 实现步骤&#xff1a; 1、打开设置 File-》Preferences-》Settings 2、具体设置 2.1、在配置中搜索 workbench.editor.showTabs 设置为multiple。 2.2、在配置中搜索 workbench.editor.enablePreview 取消勾选。 根据这个功能的说明&#xff0c;在…

Java项目-基于springcloud框架的分布式架构网上商城系统项目实战(附源码+文档)

作者&#xff1a;计算机学长阿伟 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、ElementUI等&#xff0c;“文末源码”。 开发运行环境 开发语言&#xff1a;Java数据库&#xff1a;MySQL技术&#xff1a;SpringBoot、Vue、Mybaits Plus、ELementUI工具&#xff1a;IDEA/…

背包九讲——完全背包问题

目录 完全背包问题 问题定义 动态规划解法 状态转移方程 初始化 遍历顺序 三种解法&#xff1a; 朴素版——枚举k 进阶版——dp正推&#xff08;一维滚动数组&#xff09; 背包问题第三讲——完全背包问题 背包问题是一类经典的组合优化问题&#xff0c;通常涉及在限定…

PCB走线线径与电流关系

转载自一个实验搞明白PCB走线应该画多宽_哔哩哔哩_bilibili

2011年国赛高教杯数学建模A题城市表层土壤重金属污染分析解题全过程文档及程序

2011年国赛高教杯数学建模 A题 城市表层土壤重金属污染分析 随着城市经济的快速发展和城市人口的不断增加&#xff0c;人类活动对城市环境质量的影响日显突出。对城市土壤地质环境异常的查证&#xff0c;以及如何应用查证获得的海量数据资料开展城市环境质量评价&#xff0c;研…

什么是智能电网?

智能电网&#xff08;Smart Grid&#xff09;被认为是当今电力行业发展的重要方向之一。它是传统电网与现代信息技术、通信技术和自动化技术深度融合的产物&#xff0c;旨在提高电力系统的效率、可靠性和可持续性。智能电网不仅仅是一个技术创新的名词&#xff0c;更是一个系统…

全域推广什么意思?如何搭建高效优质的全域推广服务商系统?

当前&#xff0c;全域推广一词的热度日渐升高&#xff0c;越来越多的人开始关注和计划入局这一全新项目&#xff0c;希望能够吃到第一波红利。不过&#xff0c;由于这一项目刚刚兴起&#xff0c;相关资料尚不完善&#xff0c;因此&#xff0c;绝大多数有意向入局的人都对该项目…

创客项目秀 | 基于使用 XIAO BLE Sense 和 Edge Impulse 的宠物活动跟踪器

今天为大家带来的是来自美国的创作者米顿-达斯的作品:宠物活动跟踪器.这个装置主要是为宠物主人提供关于宠物日常活动量的详尽数据&#xff0c;还能够根据宠物的独特需求&#xff0c;提供个性化的健康建议和活动指导。 项目背景 为了全面促进宠物的健康与活力&#xff0c;采用…

来可电子CAN数据记录仪通过智诊小助手TF卡记录文件导出

若想将TF卡中记录的数据文件导出可按以下的流程进行配置&#xff1a; 点击主界面中的导出选项即可进入到下图中TF卡应用界面 点击TF卡应用界面中“查看记录文件”的选项&#xff0c;进入导出文件界面。 点击“选择”进入勾选文件的界面 点击“导出”后&#xff0c;点击“确定”…

Vulnhub打靶-napping

基本信息 靶机下载&#xff1a;https://download.vulnhub.com/napping/napping-1.0.1.ova 攻击机器&#xff1a;192.168.20.128&#xff08;Windows操作系统&#xff09;& 192.168.20.138&#xff08;kali&#xff09; 提示信息&#xff1a;甚至管理员也可以在工作中睡…

统信UOS与Windows11传输数据

原文连接&#xff1a;统信UOS与Windows11相互传输数据 hello&#xff0c;大家好啊&#xff0c;今天给大家带来一篇统信UOS与Windows11之间通过共享文件夹传输数据的方法&#xff0c;首先在Windows11上创建共享文件夹&#xff0c;然后通过smb协议在UOS上进行连接访问&#xff0c…

彻底解决IDEA SpringBoot项目yml文件没有小树叶,读取配置文件失败问题

报错说没有配置dubbo:application:name,其实是配置了的&#xff0c;就是读不到&#xff0c;那有没有可能是yml文件不是绿叶的问题&#xff1f;网上查了很多文章配置小绿叶&#xff0c;最后还是报这个错&#xff0c;而且网上的文章配置小绿叶也太过于繁琐&#xff0c;其实就一招…

【Java后端】之 ThreadLocal 详解

想象一下&#xff0c;你有一个工具箱&#xff0c;里面放着各种工具。在多人共用这个工具箱的时候&#xff0c;很容易出现混乱&#xff0c;比如有人拿走了你的锤子&#xff0c;或者你找不到合适的螺丝刀。为了避免这种情况&#xff0c;最好的办法就是每个人都有自己独立的工具箱…

Wasm解析入口分析

直接postman请求&#xff0c;发现返回了一个wasm&#xff0c;需要解析这个wasm获取到参数。下面找到页面入口&#xff0c;如下&#xff1a; 也是个VM解析&#xff0c;VM太多了&#xff0c;扣出来就行&#xff0c;不难&#xff0c;就是麻烦的很。

6个最佳核心应用仪表盘构建工具

核心应用仪表盘&#xff08;Core App Dashboard&#xff09;的概念或许你不太熟悉&#xff0c;但仪表盘你一定不陌生。 从汽车的仪表盘显示速度和油量&#xff0c;到运动手环仪表盘追踪步数和心率&#xff0c;再到金融投资仪表盘监控股票和基金的实时行情&#xff0c;它们通过…