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

这篇具有很好参考价值的文章主要介绍了【.net core】yisha框架,bootstrap-table组件增加固定列功能。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

需要引入

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);

 样式及脚本存放路径

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

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

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

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

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

视图shard文件中引入:

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

 页面调用:

【.net core】yisha框架,bootstrap-table组件增加固定列功能,.netcore,bootstrap,前端文章来源地址https://www.toymoban.com/news/detail-811579.html

到了这里,关于【.net core】yisha框架,bootstrap-table组件增加固定列功能的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • .NET Core 开发微服务框架介绍

    什么是微服务? 微服务是一种系统架构模式,它将传统的单体应用程序按照业务功能拆分成多个职责单一、独立部署、松耦合、可伸缩的接口服务。每个微服务都有自己的数据存储、业务逻辑、通信机制和技术栈,可以通过标准化的协议(如 HTTP、gRPC、AMQP 等)进行交互。微

    2024年02月15日
    浏览(24)
  • 特斯拉为何使用.NET Core技术框架?

    知乎上有一个帖子非常热闹:特斯拉为何使用.NET Core技术框架?为何不用Java/Go等? 可能有很多人对.NET的印象还停留在2016年之前,认为“.NET是闭源的”“.NET就只能用Windows”,但其实.NET已经开源并实现跨平台好多年了! Linus Torvalds也因Microsoft的改变而公开宣称接纳Microsoft!

    2024年02月09日
    浏览(36)
  • C# 静态构造函数未执行 .net core框架

    代码如下,在执行Encoding.GetEncoding(“gb2312”);方法后报错,说没有找到对应编码,经测试,发现是静态构造函数未执行。 将代码改成这样就恢复正常了: 推测是编译器认为静态构造函数无用,被优化掉了。 也可能是静态函数的调用方式并非在类加载时调用,而是在实例化

    2024年02月10日
    浏览(28)
  • .NET使用一行命令轻松生成EF Core项目框架

    dotnet ef是Entity Framework Core(EF Core)的一个命令行工具,用于管理EF Core应用程序的数据库和代码。除了提供管理数据库的命令之外,dotnet ef还可以生成和管理实体和上下文代码。本文将介绍如何使用dotnet ef动态生成代码。 一、环境准备 1、项目准备 用vs2022新建一个.NET6的asp.

    2023年04月27日
    浏览(40)
  • .net core下优秀的日志框架使用解析,附源代码

    在 .NET Core 中,日志是一个非常重要的组件,它可以帮助我们记录应用程序的运行情况,以便在出现问题时进行排查。在本文中,我们将介绍五个优秀的 .NET Core 日志框架,它们分别是 Serilog、NLog、Log4Net、 Microsoft.Extensions.Logging 和 Loupe。我们将为每个框架提供使用方法及步骤

    2024年02月05日
    浏览(40)
  • asp.net core 框架搭建2-搭建MVC后台管理系统

    作者:xcLeigh 文章地址:https://blog.csdn.net/weixin_43151418/article/details/131458964 asp.net core 框架搭建2-搭建MVC后台管理系统 ,本文章介绍asp.net core框架搭建,然后开发一个后台管理系统,将一步步带着大家,实现目标。所有操作过程将展现在本篇文章,下面咋们一起来实现它吧。 使

    2024年02月12日
    浏览(32)
  • ASP.NET Core使用JWT+标识框架(identity)实现登录验证

    最近阅读了《ASP.NET Core 技术内幕与项目实战——基于DDD与前后端分离》(作者杨中科)的第八章,对于Core入门的我来说体会颇深,整理相关笔记。 JWT:全称“JSON web toke”,目前流行的跨域身份验证解决方案; 标识框架(identity):由ASP.NET Core提供的框架,它采用RBAC(role

    2024年02月11日
    浏览(33)
  • ASP.NET Core 6框架揭秘实例演示[36]:HTTPS重定向

    HTTPS是确保传输安全最主要的手段,并且已经成为了互联网默认的传输协议。不知道读者朋友们是否注意到当我们利用浏览器(比如Chrome)浏览某个公共站点的时候,如果我们输入的是一个HTTP地址,在大部分情况下浏览器会自动重定向到对应HTTPS地址。这一特性源于浏览器和

    2024年02月07日
    浏览(30)
  • 开源:Taurus.DTC 微服务分布式事务框架,支持 .Net 和 .Net Core 双系列版本

    在经过1年多的深思,十几年的框架编写技术沉淀下,花了近一个月的时间,终于又为 .Net 及 .Net Core 的微服务系列框架贡献当中的一个重要组件。 https://github.com/cyq1162/Taurus.DTC   由于 CYQ.Data Orm 组件本身支持10多种数据库,因此提供的包,只根据消息队列的需要分拆提供。 默

    2024年02月02日
    浏览(56)
  • .net core 创建WebAPI以及使用EF DBFirst框架使用方法与疑问解答(.net 6)

    EF语法包: 生成实体模型: 修改实体模型: 把生成的实体和上下文都输出到某个文件夹命令 增加JSON格式脚手架: 若想增加某个版本json脚手架,需要加入后缀如: 问题与解决方案: 1、问题: Your startup project \\\'XXX\\\' doesn\\\'t reference Microsoft.EntityFrameworkCore.Design. This package is requi

    2024年02月16日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包