解决ReportViewer的双竖滚动条的问题

来源:互联网 发布:代谢综合征临床数据库 编辑:程序博客网 时间:2024/06/05 18:08

问题描述:在使用ReportViewer绑定一个SqlServer ReportingService的一张报表后,有些内容较长的报表会出现双滚动条的问题

解决:

/*  * 移除报表页面的双滚动条 * removeReportMultipleScroll(reportId,1) 表示移除页面的滚动条,保留reportViewer的滚动条 * removeReportMultipleScroll(reportId,2) 表示移除reportViewer的滚动条,保留页面的滚动条*/var removeReportMultipleScroll = function (reportId, removeMode) {    var removePageScroll = 1,        removeReportScroll = 2,        mode = removeMode || removePageScroll;    if (mode === removePageScroll) {        // 去掉页面的滚动条        $('html').css('overflow', 'hidden');    }    var toolBarVisible = $('#reportViewer_fixedTable>tbody>tr:hidden').size() < 3;    var scrollHeight = 0;    function viewerPropertyChanged(viewer) {        if (!viewer.get_isLoading()) {            // 如果没有工具条,例如KPI没有工具条的则不用调整            if (!toolBarVisible) return;            var reportContentDiv = $('div[id$=ReportArea]').parent();            if (mode === removeReportScroll) {                // 给横向滚动条留出35px空间                reportContentDiv.css('paddingBottom', '35px');                // 只有当绘制数据的时候,才会有真实的scrollheight                if (reportContentDiv.find('table').length == 0) return;                // 只获取一次,以避免paddingBottom值累加的问题                if (scrollHeight === 0) {                    scrollHeight = reportContentDiv[0].scrollHeight;                }                // 设置为滚动长度                reportContentDiv[0].style.height = scrollHeight + "px"; // 不加px,不认,会成为100%                // 让fixedTable浮动起来,以让reportViewer的跟着变换大小                $('#' + reportId + '_fixedTable').css('float', 'left');            } else {                // 获取工具条的高度                var toolBarHeight = 0;                $('#reportViewer_fixedTable>tbody>tr:not(:last)').each(function () {                    toolBarHeight = toolBarHeight + $(this).height();                });                // 报表内容的高度等于当前窗口的高度-工具条的高度                var blankHeight = $(window).height() - toolBarHeight;                reportContentDiv.height(blankHeight);            }        }    }    var initListen = _.once(function(){  // underscorejs的once方法$find(reportId).add_propertyChanged(viewerPropertyChanged);})    // 查看报表时,开始侦听报表属性修改事件    Sys.Application.add_load(function () {initListen();// 每次点击查看报表,重新初始化滚动条高度,以重新计算scrollHeight = 0;    });};

removeReportMultipleScroll('<%=reportViewer.ClientID %>');  //使用举例