New to Telerik Reporting? Download free 30-day trial

Passing Culture Via AJAX Call From HTML5 Report Viewer

Environment

Product Progress® Telerik® Reporting
Project Type Web Application
Viewer HTML5 Viewer

Description

How to pass the desired culture through an AJAX call from the HTML5 Report Viewer client to the server.

Solution

The culture that is respected server side is taken from the deviceInfo["CurrentCulture"] and deviceInfo["CurrentUICulture"] properties. If any of these properties are not provided, its value will be taken from the culture settings of the server. Currently, the properties could be modified in the event jQuery.ajaxPrefilter that changes the options of the AJAX request before sending it. The culture is added only in the request for creating the document. The following code adds a handler for the jQuery.ajaxPrefilter event that sets the culture to the desired one. The PlaceCultureStringHere variable should be a string representing a valid culture.

<script>
    $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
        var str = originalOptions.url;
        var documentsSuffix = "documents";
        var isDocumentsUrl = (str.indexOf(documentsSuffix) == str.length - documentsSuffix.length);

        if (isDocumentsUrl) {
            var d = JSON.parse(originalOptions.data);
            d.deviceInfo["CurrentCulture"] = PlaceCultureStringHere;
            d.deviceInfo["CurrentUICulture"] = PlaceCultureStringHere;
            options.data = JSON.stringify(d);
        }
    });
</script>

The code could be placed in HTML5 Report Viewer's page.

In this article