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

news/2024/5/19 21:08:11 标签: .netcore, bootstrap, 前端

需要引入

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.niftyadmin.cn/n/5328125.html

相关文章

flutter使用get依赖实现全局loading效果,弹窗loading状态

get dialog的官网文档&#xff1a;GetDialogRoute class - dialog_route library - Dart API 可以使用Get.dialog()方法来创建一个自定义的加载弹窗&#xff0c;get框架是支持自定义弹窗效果的&#xff0c;所以我们就使用这个方式来自定义一个弹窗效果&#xff0c;并且点击遮罩…

K8s(二)Pod资源——node调度策略、node亲和性、污点与容忍度

目录 node调度策略nodeName和nodeSelector 指定nodeName 指定nodeSelector node亲和性 node节点亲和性 硬亲和性 软亲和性 污点与容忍度 本文主要介绍了在pod中&#xff0c;与node相关的调度策略&#xff0c;亲和性&#xff0c;污点与容忍度等的内容 node调度策略node…

深度学习笔记(四)——使用TF2构建基础网络的常用函数+简单ML分类实现

文中程序以Tensorflow-2.6.0为例 部分概念包含笔者个人理解&#xff0c;如有遗漏或错误&#xff0c;欢迎评论或私信指正。 截图和程序部分引用自北京大学机器学习公开课 TF2基础常用函数 1、张量处理类 强制数据类型转换&#xff1a; a1 tf.constant([1,2,3], dtypetf.floa…

收银系统源码-智慧新零售系统框架

智慧新零售系统是一套线下线上打通的收银系统&#xff0c;主要给门店提供含线下收银、线上小程序商城、ERP进销存、精细化会员管理、丰富营销插件等为一体的智慧行业解决方案。智慧新零售系统有合伙人、代理商、商户、门店、收银员/导购员等角色&#xff0c;每个角色有相应的权…

Apache StringUtils:Java字符串处理工具类

简介 在我们的代码中经常需要对字符串判空&#xff0c;截取字符串、转换大小写、分隔字符串、比较字符串、去掉多余空格、拼接字符串、使用正则表达式等等。如果只用 String 类提供的那些方法&#xff0c;我们需要手写大量的额外代码&#xff0c;不然容易出现各种异常。现在有…

构建未来教育:在线培训系统开发的技术探讨

随着远程学习的崛起和数字化教育的普及&#xff0c;在线培训系统的开发成为了现代教育的核心。本文将深入讨论在线培训系统的关键技术要点&#xff0c;涵盖前后端开发、数据库管理、以及安全性和身份验证等关键方面。 前端开发&#xff1a;提供交互性与用户友好体验 在构建在…

图书管理系统:从数据库设计到前端展示的实战经验分享

✍✍计算机编程指导师 ⭐⭐个人介绍&#xff1a;自己非常喜欢研究技术问题&#xff01;专业做Java、Python、微信小程序、安卓、大数据、爬虫、Golang、大屏等实战项目。 ⛽⛽实战项目&#xff1a;有源码或者技术上的问题欢迎在评论区一起讨论交流&#xff01; ⚡⚡ Java实战 |…

Pandas实战100例 | 案例 54: 日期时间运算

案例 54: 日期时间运算 知识点讲解 当处理带有 datetime 类型数据的 DataFrame 时&#xff0c;Pandas 提供了多种方法来提取和计算日期时间组件。这包括提取年份、月份、日期、星期几以及小时等。 提取日期时间组件: 使用 .dt 访问器&#xff0c;可以从 datetime 类型的列中…