表格固定尾列dataTable.fixedColumns.js bower安装的相关问题

本文介绍了freeze-table和TableFreeze.js等表格冻结插件的使用方法及局限性,并详细解析了基于jQuery的TableFreeze.js插件的配置选项,最后分享了使用dataTable.fixedColumns.js解决动态表格冻结问题的经验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

freeze-table

Options

TableFreeze.js

TableFreeze.js(基于JQuery的表格冻结插件)

11月24日

datatable

fixedColumns.js


遇到需求固定表格尾列,尾列是操作(查看,删除)这些

尝试了css,js,jquery,插件,layui,elementui各种都没用

freeze-table

freeze-table(一个固定表格插件)

npm install -g bower

bower -v

有版本显示就成功

①在用bower install /update xxx 时出现 “EINVALID Name must be lowercase, can contain digits, dots, dashes, "@" or spaces”问题。

这个是说目录的名字有问题,我起的名字目录名html&css,中间&触发了这个报错,删掉就没了

卡这两行不动了

ctrl+c强制停止运行,再运行一遍试试

 使用

别忘了先导jQuery的js 

 具体使用

yidas/jquery-freeze-table Demo

Options

Options could be passed via JavaScript with object.

NameTypeDefaultDescription
freezeHeadbooleantrueEnable to freeze <thead>
freezeColumnbooleantrueEnable to freeze column(s)
freezeColumnHeadbooleantrueEnable to freeze column(s) head (Entire column)
scrollBarbooleanfalseEnable fixed scrollBar for X axis
fixedNavbarstring|jQuery|Element'.navbar-fixed-top'Fixed navbar deviation consideration. Example'#navbar'
scrollablebooleanfalseEnable Scrollable mode for inner scroll Y axis
fastModebooleanfalseEnable Fast mode for better performance but less accuracy
namespacestring'freeze-table'Table namespace for unbind
containerstring|jQuery|ElementfalseSpecify a document role element that contains the table. Default container is window. This option is particularly useful in that it allows you to position the table in the flow of the document near the triggering element - which will make the freeze table support in containers such as Bootstrap Modal. Example'#myModal'
columnNuminteger1The number of column(s) for freeze
columnKeepbooleanfalseFreeze column(s) will always be displayed to support interactive table
columnBorderWidthinterger1The addon border width for freeze column(s)
columnWrapStylesobjectnullCustomized CSS styles for freeze column(s) wrap. {'style': 'value'}
headWrapStylesobjectnullCustomized CSS styles for freeze head(s) wrap. {'style': 'value'}
columnHeadWrapStylesobjectnullCustomized CSS styles for freeze column-head wrap. {'style': 'value'}
callbackfunctionnullPlugin after initialization callback function
shadowbooleanfalseEnable default box-shadow UI
backgroundColorstring|boolean'white'Default table background color for Boostrap transparent UI. white#FFFFFFrgb(255,255,255,1), or false to skip.

TableFreeze.js

上面这玩意不太行,下面这个厉害,

FrozenTable(上,下,左,右)可以填数字固定任意地方多少行、列

(题外话,要是有插件还能在此基础固定任意行任意列就好了)0。0

TableFreeze.js(基于JQuery的表格冻结插件)

这个好用

看效果

TableFreeze表格冻结 (christopherkeith.github.io)

源代码

GitHub - CHristopherkeith/TableFreeze

结局 :还是没用,但是上面这个插件功能确实强大,原因是表格的内容是对接后端动态生成的,

而且渲染优先级高,也就是是相当于在原来表格上面贴图了,加载有问题时页面只有表格第一行表头,过长滑动时第一行也定死不动,只能从js动态加载的代码处想办法了。

11月24日

datatable

今天解决了,原来项目早预留了插件dataTable.fixedColumns.js

先聊一下datatable

dataTableId(表格的id),项目中是<table class="display my-table dataTable" width="100%" id="dataTable">

dom(定义DataTables的组件元素的显示和显示顺序)

项目中是domStr         var domStr = "rt<'row'<'col-sm-3'l><'col-sm-3'i><'col-sm-6'p>>";

sort(是否排序)定义的是sortflag,项目中false

lengthMenu(定义每页显示记录数select中显示的选项)项目中是[15, 30, 50]

实际展示:

 

pagingType分页风格参数:

 

项目中是full_numbers

lengthChange(是否允许用户改变表格每页显示的记录数)

项目中是true

language.url从远程文件读取国际化信息

项目中是language: {
    url: "../static/dataTables/resources/zh_ZH.txt"//
},

发现是一个分页的txt文件:

{
"processing": "<div class='black_overlay'></div><div class='fixed_div_process'><div class='loading_img'><img src='../common/images/blue-loading.gif'/></div><div class='loading_text'> 加载中,请稍候……<div></div>",
"lengthMenu": "每页显示 _MENU_ 条记录",
"zeroRecords": "没有吻合的记录!",
"info": "<div class='fixed_div_info'>当前显示 _START_ _END_ 条,共 _TOTAL_ 条记录<div>",
"infoEmpty": "显示00条记录",
"emptyTable": "暂无数据存在!",
"infoFiltered": "数据表中共为 _MAX_ 条记录",
"infoPostFix": "",
"search": "搜索",
"url": "",
"paginate": {
"first":    "首页",
"previous": "上一页",
"next":     "下一页",
"last":     "末页"
}
}

ajax(从一个ajax数据源读取数据给表格内容)

项目中是ajax: {
    url: dataUrl,
    type: "post",
    data: dataCallback
},

dataUrl'../datasource/initDatasource.action?ran=' + Math.random()

dataCallback

function dataCallback(d) {
    d.dsName = $("#dsName").val();
    d.dsIP = $("#dsIP").val();
    d.dsType = $("#dsType").val();
    d.systemName = $("#systemName").val();
    d.sysNum = $("#sysNum").val();
    d.operationDepartment = $("#operationDepartment").val();
    d.port = $("#port").val();
    d.databaseName = $("#databaseName").val();
}

这函数应该是做查询的,绑定input的id返回数据给后端查询

 

 

columns(设定列的所有属性)

注意,如果是使用 columns来定义列,那么你的th有多少,就要定义多个个(如果你不指定任何选项可以为null)

项目中定义的dataColumns

 

columnDefs(这个参数是一个列定义对象数组,和 columns 参数很像,这个参数允许你给指定列设置选项,应用到一个或多个列。而不像 columns 需要每列都要定义)

项目中是columnSortDefs   var columnSortDefs = [];  好像什么都没设置

createdRow(当tr元素被创建(所有的td元素已经插入进去),或者给tr绑定事件,该回调函数被执行,允许操作tr元素)

项目中定义的是createdRowCallback

 

这里对回调函数做了双重保险

这个回调函数是在表格数据都导入后,在最后一列生成操作的相关按钮

 

DataTables是一个可高度配置化的类库,可以在生成HTML tables过程中的所有方面实现定制。所有特性可以通过打开、关闭或者定制来满足你对表格所有的要求。 定制要先定义一个options,然后传入$().DataTable()构造函数,通过定制options的内容来实现定制。

生成表格的关键代码

fixedColumns.js

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码老祖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值