当前位置: 首页 > news >正文

BootstrapTable处理表格

需求背景

历史项目使用 BootstrapTable 作为前端组件
应客户需要调整:

  • 冻结前四列
  • 对于大文本文字显示部分内容,鼠标悬浮显示完整内容

冻结列

1、引入相关CSS,JS

CSS

<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/plugins/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="/editor-app/css/bootstrap-table-fixed-columns.css">

JS

<script src="/js/plugins/bootstrap-table/bootstrap-table.js"></script>
<script src="/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/editor-app/libs/bootstrap-table-fixed-columns.js"></script>

完整示例

<!DOCTYPE html>
<html xmlns:shiro="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.w3.org/1999/xhtml">
<html>
<meta charset="utf-8">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/plugins/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="/editor-app/css/bootstrap-table-fixed-columns.css">
<style>
</style>
<head th:include="include :: header"></head>
<body class="gray-bg"><div class="wrapper wrapper-content "><table style="width: 100%;"></table><div class="row"><div class="col-sm-12 select-table table-striped"><table id="***Table" data-mobile-responsive="true"></table></div></div></div><!--shiro控制bootstraptable行内按钮看见性  --></div><div th:include="include :: footer"></div><script src="/js/plugins/bootstrap-table/bootstrap-table.js"></script><script src="/js/plugins/bootstrap-table/bootstrap-table.min.js"></script><script src="/editor-app/libs/bootstrap-table-fixed-columns.js"></script><script type="text/javascript" src="/js/appjs/***test.js"></script>
</body>
</html>
2、对应BootstrapTable增加冻结列属性

fixedColumns: true, //是否开启冻结列
fixedNumber: 4, //冻结列数

完整示例

function load() {$('#***Table').bootstrapTable({id: "***Table",type: 0, // 0 代表bootstrapTable 1代表bootstrapTreeTablemethod: 'get', // 服务器数据的请求方式 get or posturl: prefix + "/list", // 服务器数据的加载地址exportUrl: prefix + "/export",//	showRefresh : true,//	showToggle : true,//	showColumns : true,fixedColumns: true, //是否开启冻结列fixedNumber: 4, //冻结列数iconSize: 'outline',toolbar: 'toolbar',striped: true, // 设置为true会有隔行变色效果dataType: "json", // 服务器返回的数据类型pagination: true, // 设置为true会在底部显示分页条// queryParamsType : "limit",// //设置为limit则会发送符合RESTFull格式的参数singleSelect: false, // 设置为true将禁止多选// contentType : "application/x-www-form-urlencoded",// //发送到服务器的数据编码类型pageSize: 5, // 如果设置了分页,每页数据条数pageNumber: 1, // 如果设置了分布,首页页码//search : true, // 是否显示搜索框showColumns: false, // 是否显示内容下拉框(选择显示的列)sidePagination: "server", // 设置在哪里进行分页,可选值为"client" 或者 "server"queryParams: function (params) {return {//说明:传入后台的参数包括offset开始索引,limit步长,sort排序列,order:desc或者,以及所有列的键值对limit: params.limit,offset: params.offset,year:$('#year').val(),companyName:$('#companyName').val(),};},columns: [{field: 'projectId',visible: false,},{field: 'year',title: '年度批次',halign: 'center',align: 'center',width:'73px'},{field: 'type',title: '项目类型',halign: 'center',align: 'center',width:'72px'},//........{title: '操作',field: 'id',align: 'center',formatter: function (value, row, index) {var e = '<a href="###" style="color: #00a3ff" title="编辑" οnclick="edit(\''+ row.projectId+ '\')">编辑</a> ';return e;}}]});
}

实现效果
N列固定前四列

控制大文本显示部分,鼠标悬浮显示完整内容

处理前
在这里插入图片描述

处理后
在这里插入图片描述

实现方案

在对应列增如下属性

{field: 'other',title: '其他',halign: 'center',align: 'center',cellStyle: function (value, row, index) {return {css: {"min-width": "40px","white-space": "nowrap","text-overflow": "ellipsis","overflow": "hidden","max-width": "120px"}}},formatter: function (value, row, index) {console.log(value);var span = document.createElement('span');span.setAttribute('title', value);span.innerHTML = value;return span.outerHTML;}}
http://www.lryc.cn/news/513724.html

相关文章:

  • UniApp 打开文件工具,获取文件类型,判断文件类型
  • docker-开源nocodb,使用已有数据库
  • Mysql COUNT() 函数详解
  • 单周期CPU电路设计
  • 从零开始采用命令行创建uniapp vue3 ts springboot项目
  • 跟着逻辑先生学习FPGA-实战篇第一课 6-1 LED灯闪烁实验
  • springboot 跨域配置
  • C语言宏和结构体的使用代码
  • 微信小程序 覆盖组件cover-view
  • 【Redis知识】Redis进阶-redis还有哪些高级特性?
  • 【Pytorch实用教程】深入了解 torchvision.models.resnet18 新旧版本的区别
  • 攻防世界 - Web - Level 3 | very_easy_sql
  • 使用Java Selenium修改打开页面窗口大小
  • 基于BiLSTM和随机森林回归模型的序列数据预测
  • 【Vim Masterclass 笔记04】S03L12:Vim 文本删除同步练习课 + S03L13:练习课点评
  • [AI] 深度学习的“黑箱”探索:从解释性到透明性
  • 网络安全技能试题总结参考
  • 【翻译】优化加速像素着色器执行的方法
  • 赛博周刊·2024年度工具精选(图片资源类)
  • 【深度学习基础之多尺度特征提取】多尺度图像增强(Multi-Scale Image Augmentation)是如何在深度学习网络中提取多尺度特征的?附代码
  • Spring Boot项目启动时显示MySQL连接数已满的错误
  • 小程序多入口对应指定客服的实现方案:小程序如何实现接入指定客服人员?
  • 网页单机版五子棋小游戏项目练习-初学前端可用于练习~
  • 【玩转23种Java设计模式】行为型模式篇:命令模式
  • 【Spring MVC 常用注解】注解驱动开发的魔法
  • jmeter分布式启动
  • 数据仓库中的指标体系模型介绍
  • 混合合并两个pdf文件
  • aws(学习笔记第二十一课) 开发lambda应用程序
  • JavaWeb Servlet的getInitParameter、业务层、控制反转IOC和依赖注入DI