2

我已经使用 html 渲染在 mvc 中实现了一个报告引擎。我必须根据通过 render 方法返回的元数据创建自定义分页功能。我现在正在考虑以同样的方式实现交互式排序,这看起来像是一项更艰巨的任务。似乎HTML 设备信息设置标题中有一个用于 html 渲染的设置,称为ActionScript

ActionScript(*) - 指定发生动作事件时要使用的 JavaScript 函数的名称,例如钻取或书签单击。如果指定了此参数,则操作事件将触发指定的 JavaScript 函数,而不是回发到服务器。

我的问题是有人用过这个功能吗?由于在呈现报告后我失去了身份验证,我将不得不以某种方式在控制器中进行经过身份验证的回调。在我看来,在报告中添加用于排序的参数可能更容易,但是我想在报告中保留交互式排序。

--编辑解决方案1---

事实证明,上面脚本名称旁边的 * 表示 ActionScript 参数在 ssrs 2012 之后正在贬值。因此,我决定不去追求它。如果其他人偶然发现了这一点,那么我想到的在没有回发的情况下模拟交互式排序的最佳方法如下详述:

关于报告

1. Add a parameter to the report SortField1
2. Add a Sort condition to the Tablix or group you wish to sort. Tablix-Sort Expressions
3. Set the expression of the sort to Fields(Paremeters!SortField1.Value).Value
4. Set the default value of parameter SortField1 to the default sort field
5. Set Allow Nulls of the parameter to true.
6. Add a image or label for each column you would like to sort by
7. Create a action for the element created in step 7 with code similar to
  ="javascript:void(reportSortRequest('ColumsFieldName'))"
 NOTE: Your view or view descendant will have need to have an identical function defined to accept the action 

在视图中

  1. 实现函数reportSortRequest(fieldName)。这应该设置 Model.SortField1 并将帖子调用回控制器以重新呈现报告。

在控制器中(这是用于发送将具有字段 SortField1 的模型的 Ajax 回发)

  1. 使用包括 SortField1 在内的报告信息调用渲染。

更新了用于访问报告标记包装器的客户端脚本。

ssrs 标记生成的报告元素可以在您的视图中通过其标记进行访问。我发现以下内容将使用预定的 ssrs 包装元素#oReportCell工作:

加载到 iframe 中:

var frameContent = $("#myIFrame").contents();        
var ssrsContentElement = frameContent.find("#oReportCell");

加载到 div 中:

var ssrsContentElement = $("#myDiv").find("#oReportCell");

将 html blob 加载到框架或 div 中的函数。根据报告的配置方式,内容是临时文件的 url 或 html 标记。

function setReportContent(content, isUrl, renderInIFrame) {        
    if (isUrl) {
        if (renderInIFrame) {
            $("#reportContent").html("<iframe id='reportFrame' sandbox='allow-same-origin allow-scripts' width='100%' height='300' scrolling='yes' onload='onReportFrameLoad();'\></iframe>");
            $('#reportFrame').attr('src', content);               
        }
        else 
            $("#reportContent").load(content);              

    }
    else {
        if (renderInIFrame) {
            $("#reportContent").html("<iframe id='reportFrame' sandbox='allow-same-origin allow-scripts' width='100%' height='300' scrolling='yes' onload='onReportFrameLoad();'\></iframe>");               
            $('#reportFrame').contents().find('html').html(content);
        }
        else      
            $("#reportContent").html(content);            
    }
    if(!renderInIFrame)
        showReportWaitIndicator(false);
    $("#reportContent").show();
}

请注意,如果您希望正确呈现设置了 auto-resize 属性的报告图像,则必须打开allow-scripts以便 ssrs resize js 函数可以触发,请小心。

4

0 回答 0