【.net core】yisha框架,bootstrap-table组件增加固定列功能

news2024/10/1 1:17:04

需要引入

bootstrap-table-fixed-columns.css和bootstrap-table-fixed-columns.js文件

文件代码:

bootstrap-table-fixed-columns.css样式文件代码

.fixed-table-header-columns,
.fixed-table-body-columns {
    position: absolute;
    background-color: #fff;
    display: none;
    box-sizing: border-box;
    overflow: hidden;
}

.fixed-table-header-columns .table,
.fixed-table-body-columns .table {
    border-right: 1px solid #ddd;
}

.fixed-table-header-columns .table.table-no-bordered,
.fixed-table-body-columns .table.table-no-bordered {
    border-right: 1px solid transparent;
}

.fixed-table-body-columns table {
    position: absolute;
    animation: none;
}

.bootstrap-table .table-hover > tbody > tr.hover > td{
    background-color: #f5f5f5;
}

bootstrap-table-fixed-columns.js脚本文件代码:

/**
 * @author congye ma
 */

(function ($) {
    'use strict';

    $.extend($.fn.bootstrapTable.defaults, {
        fixedColumns: false,
        fixedNumber: 1,
        fixedFrom: 'right'//left
    });

    var BootstrapTable = $.fn.bootstrapTable.Constructor,
        _initHeader = BootstrapTable.prototype.initHeader,
        _initBody = BootstrapTable.prototype.initBody,
        _resetView = BootstrapTable.prototype.resetView;

    BootstrapTable.prototype.initFixedColumns = function () {
        this.$fixedHeader = $([
            '<div class="fixed-table-header-columns">',
            '<table>',
            '<thead></thead>',
            '</table>',
            '</div>'].join(''));

        this.timeoutHeaderColumns_ = 0;
        this.$fixedHeader.find('table').attr('class', this.$el.attr('class'));
        this.$fixedHeaderColumns = this.$fixedHeader.find('thead');
        this.$tableHeader.before(this.$fixedHeader);

        this.$fixedBody = $([
            '<div class="fixed-table-body-columns">',
            '<table>',
            '<tbody></tbody>',
            '</table>',
            '</div>'].join(''));

        this.timeoutBodyColumns_ = 0;
        this.$fixedBody.find('table').attr('class', this.$el.attr('class'));
        this.$fixedBodyColumns = this.$fixedBody.find('tbody');
        this.$tableBody.before(this.$fixedBody);
        if (this.options.fixedFrom == 'right') {
            this.$fixedHeader.css({ right: 6 });
            this.$fixedBody.css({ right: 6 })
        }
    };

    BootstrapTable.prototype.initHeader = function () {
        _initHeader.apply(this, Array.prototype.slice.apply(arguments));

        if (!this.options.fixedColumns) {
            return;
        }

        this.initFixedColumns();

        var that = this, $trs = this.$header.find('tr').clone();
        $trs.each(function () {
            if (that.options.fixedFrom == 'right') {
                var index = that.options.columns[0].length - Math.abs(parseInt(that.options.fixedNumber));
                $(this).find('th:lt(' + index + ')').remove();

            } else {
                $(this).find('th:gt(' + that.options.fixedNumber + ')').remove();
            }

        });
        this.$fixedHeaderColumns.html('').append($trs);
    };

    BootstrapTable.prototype.initBody = function () {
        _initBody.apply(this, Array.prototype.slice.apply(arguments));

        if (!this.options.fixedColumns) {
            return;
        }

        var that = this,
            rowspan = 0;

        this.$fixedBodyColumns.html('');
        this.$body.find('> tr[data-index]').each(function () {
            var $tr = $(this).clone(),
                $tds = $tr.find('td');

            $tr.html('');
            if (that.options.fixedFrom == 'right') {
                var end = that.options.columns[0].length - Math.abs(parseInt(that.options.fixedNumber));
            } else {
                var end = that.options.fixedNumber;
            }

            if (rowspan > 0) {
                --end;
                --rowspan;
            }
            if (that.options.fixedFrom == 'right') {
                for (var i = end; i < that.options.columns[0].length; i++) {
                    $tr.append($tds.eq(i).clone());
                }
            } else {
                for (var i = 0; i < end; i++) {
                    $tr.append($tds.eq(i).clone());
                }
            }

            that.$fixedBodyColumns.append($tr);

            if ($tds.eq(0).attr('rowspan')) {
                rowspan = $tds.eq(0).attr('rowspan') - 1;
            }
        });
    };

    BootstrapTable.prototype.resetView = function () {
        _resetView.apply(this, Array.prototype.slice.apply(arguments));

        if (!this.options.fixedColumns) {
            return;
        }

        clearTimeout(this.timeoutHeaderColumns_);
        this.timeoutHeaderColumns_ = setTimeout($.proxy(this.fitHeaderColumns, this), this.$el.is(':hidden') ? 100 : 0);

        clearTimeout(this.timeoutBodyColumns_);
        this.timeoutBodyColumns_ = setTimeout($.proxy(this.fitBodyColumns, this), this.$el.is(':hidden') ? 100 : 0);
    };

    BootstrapTable.prototype.fitHeaderColumns = function () {
        var that = this,
            visibleFields = this.getVisibleFields(),
            headerWidth = 0;
        if (that.options.fixedFrom == 'right') {
            var trs = [].slice.call(this.$body.find('tr:first-child:not(.no-records-found) > *'));
            var $trs = $(trs.reverse());
            $trs.each(function (i) {
                var $this = $(this);
                var index = i;
                if (i >= Math.abs(that.options.fixedNumber)) {
                    return false;
                }

                if (that.options.detailView && !that.options.cardView) {
                    index = i - 1;
                }
                that.$fixedHeader.find('th[data-field="' + visibleFields[$trs.length - 1 + index] + '"]')
                    .find('.fht-cell').width($this.innerWidth());
                headerWidth += $this.outerWidth();
            });
            that.$header.find('> tr').each(function (i) {
                that.$fixedHeader.height($(this).height());
            });
        } else {
            this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
                var $this = $(this),
                    index = i;
                if (i >= that.options.fixedNumber) {
                    return false;
                }
                if (that.options.detailView && !that.options.cardView) {
                    index = i - 1;
                }
                that.$fixedHeader.find('th[data-field="' + visibleFields[index] + '"]')
                    .find('.fht-cell').width($this.innerWidth());
                headerWidth += $this.outerWidth();
            });
        }
        this.$fixedHeader.width(headerWidth + 1).show();
    };

    BootstrapTable.prototype.fitBodyColumns = function () {
        var that = this,
            top = -(parseInt(this.$el.css('margin-top')) - 2),
            // the fixed height should reduce the scorll-x height
            height = this.$body[0].offsetWidth > 1650 ? this.$tableBody.height() - 6 : this.$tableBody.height();//处理X方向滚动条时底部出现重复内容情况
            //console.log('dom', this.$body[0].offsetWidth, this.$tableBody)
        if (!this.$body.find('> tr[data-index]').length) {
            this.$fixedBody.hide();
            return;
        }

        if (!this.options.height) {
            top = this.$fixedHeader.height();
            console.log("fitBodyColumns header Height" + top);
            height = height - top;
        }

        // height = this.$tableBody.find("tbody").height();
        this.$fixedBody.css({
            width: this.$fixedHeader.width(),
            height: height,
            top: top
        }).show();

        this.$body.find('> tr').each(function (i) {
            that.$fixedBody.find('tr:eq(' + i + ')').height($(this).height());
        });

        // events
        this.$tableBody.on('scroll', function () {
            that.$fixedBody.find('table').css('top', -$(this).scrollTop());
        });
        this.$body.find('> tr[data-index]').off('hover').hover(function () {
            var index = $(this).data('index');
            that.$fixedBody.find('tr[data-index="' + index + '"]').addClass('hover');
        }, function () {
            var index = $(this).data('index');
            that.$fixedBody.find('tr[data-index="' + index + '"]').removeClass('hover');
        });
        this.$fixedBody.find('tr[data-index]').off('hover').hover(function () {
            var index = $(this).data('index');
            that.$body.find('tr[data-index="' + index + '"]').addClass('hover');
        }, function () {
            var index = $(this).data('index');
            that.$body.find('> tr[data-index="' + index + '"]').removeClass('hover');
        });
        fixFixedRightColumnsEvents.call(this);
    };

    function fixFixedRightColumnsEvents() {
        var that = this;
        if (this.options.fixedFrom == 'right') {
            var fixedBeginIndex = that.options.columns[0].length - 1 - that.options.fixedNumber;
            $.each(this.header.events, function (i, events) {
                if (i < fixedBeginIndex) {
                    return;
                }
                if (!events) {
                    return;
                }
                // fix bug, if events is defined with namespace
                if (typeof events === 'string') {
                    events = calculateObjectValue(null, events);
                }

                var field = that.header.fields[i];
                var fieldIndex = $.inArray(field, that.getVisibleFields());

                if (fieldIndex === -1) {
                    return;
                }

                if (that.options.detailView && !that.options.cardView) {
                    fieldIndex += 1;
                }

                for (var key in events) {
                    that.$fixedBodyColumns.find('>tr:not(.no-records-found)').each(function () {
                        var $tr = $(this),
                            $td = $tr.find(that.options.cardView ? '.card-view' : 'td').eq(fieldIndex - fixedBeginIndex - 1),
                            index = key.indexOf(' '),
                            name = key.substring(0, index),
                            el = key.substring(index + 1),
                            func = events[key];

                        $td.find(el).off(name).on(name, function (e) {
                            var index = $tr.data('index'),
                                row = that.data[index],
                                value = row[field];

                            func.apply(this, [e, value, row, index]);
                        });
                    });
                }
            });
        }

    }

})(jQuery);

 样式及脚本存放路径

项目bundleconfig.json文件修改内容为图片中红框标记内容

yisha-jquery-bootstrap-table-plugin.js脚本文件修改内容,在红框标记的方法内增加标记参数 

 

视图shard文件中引入:

 页面调用:

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

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

相关文章

企业知识库搭建全流程,中小型企业必看

知识库是企业知识管理和信息查询的重要平台&#xff0c;对企业效率提升&#xff0c;业务流程规范和企业文化建设有着重要的影响。那么&#xff0c;如何为企业搭建一个合适&#xff0c;高效&#xff0c;易用的知识库呢&#xff1f;接下来就为中小型企业详解企业知识库搭建全流程…

C++力扣题目257--二叉树的所有路径

给你一个二叉树的根节点 root &#xff0c;按 任意顺序 &#xff0c;返回所有从根节点到叶子节点的路径。 叶子节点 是指没有子节点的节点。 示例 1&#xff1a; 输入&#xff1a;root [1,2,3,null,5] 输出&#xff1a;["1->2->5","1->3"]示例 …

养猫家庭怎么挑选宠物空气净化器?猫用空气净化器推荐来了!

宠物空气净化器在近年来越来越受到关注&#xff0c;它们被宣传为解决宠物家庭空气质量问题的神器。然而&#xff0c;一些人认为宠物空气净化器只是商家们利用人们对宠物的爱而推出的一种所谓的“智商税”&#xff0c;那么作为一位养猫多年的铲屎官&#xff0c;我可以说宠物空气…

【AI视野·今日Sound 声学论文速览 第四十五期】Wed, 10 Jan 2024

AI视野今日CS.Sound 声学论文速览 Wed, 10 Jan 2024 Totally 12 papers &#x1f449;上期速览✈更多精彩请移步主页 Daily Sound Papers Masked Audio Generation using a Single Non-Autoregressive Transformer Authors Alon Ziv, Itai Gat, Gael Le Lan, Tal Remez, Felix…

2024 爱分析 · AI 与大模型高峰论坛:和鲸喜获两项殊荣!

1 月 9 日下午&#xff0c;“2024 爱分析 AI 与大模型高峰论坛”在京举办。本次论坛以“智能涌现&#xff0c;价值焕新”为主题&#xff0c;汇聚众多专家学者、实践先驱&#xff0c;共同探讨 AI 与大模型在企业内的新场景、新价值、新路径。论坛中&#xff0c;和鲸科技成功入选…

【数据链路层】802.11无线局域网的基本概述(湖科大慕课自学笔记)

802.11无线局域网基本概述 1&#xff1a;无线局域网&#xff08;WLAN&#xff09; 1&#xff1a;基本概述 2&#xff1a;802.11无线局域网可以分为以下两类 有固定基础设施的与无固定基础设施的 固定基础设施是指 我们来举例说明&#xff1a; 2&#xff1a;有固定基础设施…

SAP存放状态的几个常用表

SAP存放状态的几个常用表 在sap中&#xff0c;包括订单、项目、计划、设备主数据等&#xff0c;存在审批流程的业务单据&#xff0c;这些业务对象都会有状态的属性&#xff0c;用来控制和约束该业务当前的操作。 主要的表 JEST&#xff1a;存放了该对象编号的当前状态 JCDS…

蓝奏云获取下载链接js逆向

本期地址如下&#xff0c;使用base64解密获得 aHR0cHM6Ly9meGpkLmxhbnpvdXcuY29tL2l6bkxrMTdncnkyZA 获取最终的下载链接需要经过三次请求获得&#xff0c;如下图 每个请求都包含下一次请求的信息&#xff0c;我们逐步分析请求 第一个请求直接包含了第二次请求的src 第二个请…

团结引擎的安装

团结引擎有多种方式可以安装&#xff0c;具体可以参考团结引擎官方文档&#xff0c;这里我们使用最简单的安装方式&#xff0c;通过团结Hub来安装。 1. 安装 Tuanjie Hub 进入团结引擎官网&#xff0c;点击右上角的【下载Unity】&#xff0c;进入下载界面&#xff0c;选择“下载…

react使用recoil进行全局状态管理 + axios进行网络请求

我们尝试使用recoil进行全局状态管理以及axios进行网络请求。 recoil recoil是facebook官方推出的新的react状态管理方案&#xff0c;采用分散管理原子状态的设计模式&#xff0c;同时也强调immuteable&#xff08;mobx则是mutable&#xff09;&#xff0c;这与react强调immu…

jQuery文字洗牌动效

html代码 效果展示 jQuery文本洗牌效果插件 <div class"container"><p class"lead">文本洗牌动画特效</p><h1 id"basic">A time to seek,</h1><h1 id"custom">and a time to lose;</h1> &…

5G前装搭载率即将迈过10%大关,车载通讯进入多层次增长通道

对于智能化来说&#xff0c;车载通讯性能的提升&#xff0c;对于相关功能的用户体验优化、进一步减少通讯时延以及打开应用新空间&#xff0c;至关重要。 目前&#xff0c;2G/3G正在进入运营商逐步关闭运营的阶段&#xff0c;4G依然是主力&#xff0c;但5G也在迎来新的增长机会…

1. seaborn-可视化统计关系

统计分析是了解数据集中的变量如何相互关联以及这些关系如何依赖于其他变量的过程。可视化是此过程的核心组件&#xff0c;这是因为当数据被恰当地可视化时&#xff0c;人的视觉系统可以看到指示关系的趋势和模式。 这里介绍三个seaborn函数。我们最常用的是relplot()。这是一…

FPGA开发设计

一、概述 FPGA是可编程逻辑器件的一种&#xff0c;本质上是一种高密度可编程逻辑器件。 FPGA的灵活性高、开发周期短、并行性高、具备可重构特性&#xff0c;是一种广泛应用的半定制电路。 FPGA的原理 采用基于SRAM工艺的查位表结构&#xff08;LUT&#xff09;&#xff0c;…

WPF 入门教程DispatcherTimer计时器

https://www.zhihu.com/tardis/bd/art/430630047?source_id1001 在 WinForms 中&#xff0c;有一个名为 Timer 的控件&#xff0c;它可以在给定的时间间隔内重复执行一个操作。WPF 也有这种可能性&#xff0c;但我们有DispatcherTimer控件&#xff0c;而不是不可见的控件。它几…

FridaHook(三)——AllSafe App wp

By ruanruan&#xff0c;2022/04/21 文章目录 1、不安全的日志记录2、硬编码3、pin绕过&#xff08;1&#xff09;反编译查看方法判断逻辑&#xff08;2&#xff09;hook方法A、Hook areEqual(Object,Object)B、Hook checkPin(a) &#xff08;3&#xff09;页面效果&#xff08…

day-07 统计出现过一次的公共字符串

思路 用哈希表统计words1和words2中各个字符串的出现次数&#xff0c;次数皆为1的字符串符合题意 解题方法 //用于存储words1中各个字符串的出现次数 HashMap<String,Integer> hashMap1new HashMap<>(); //用于存储words2中各个字符串的出现次数 HashMap<Stri…

适合PC端的7款最佳时间规划、项目管理软件

分享PC端7类主流的时间管理规划软件&#xff1a;PingCode、Worktile、Todoist、Pomodoro Timer 、Toggl等。 一、时间管理软件的类型 时间管理软件可以根据其功能和应用场景被划分为几种不同的类型。每种类型的软件都旨在帮助用户以不同的方式更有效地管理和分配他们的时间。以…

leetcode 每日一题 2024年01月11日 构造有效字符串的最少插入数

题目 2645. 构造有效字符串的最少插入数 给你一个字符串 word &#xff0c;你可以向其中任何位置插入 “a”、“b” 或 “c” 任意次&#xff0c;返回使 word 有效 需要插入的最少字母数。 如果字符串可以由 “abc” 串联多次得到&#xff0c;则认为该字符串 有效 。 示例 …

day1·算法-双指针

今天是第一天&#xff0c;GUNDOM带你学算法&#xff0c;跟上我的节奏吗&#xff0c;一起闪击蓝桥杯&#xff01; 正文展开&#xff0c;今天先上点小菜供大家想用&#xff0c;如有错误或者建议直接放评论区&#xff0c;我会一个一个仔细查看的哦。 双方指针问题一般是在数组中…