Available in the Full Version

Data Grid - JsRender Integration

Employee IDNameImageTitleLanguagesPhoneCountryBirth Date
1 Nancy DavolioSales Representative
English
Russian
(206) 555-9857 USA12/8/1948
2 Andrew FullerVice President, Sales
English
German
(206) 555-9482 USA2/19/1952
3 Janet LeverlingSales Representative
English
(206) 555-3412 USA8/30/1963
4 Margaret PeacockSales Representative
English
Spanish
(206) 555-8122 USA9/19/1937
5 Steven BuchananSales Manager
English
Italian
(71) 555-4848 UK3/4/1955
6 Michael SuyamaSales Representative
English
Portuguese
(71) 555-7773 UK7/2/1963
7 Robert KingSales Representative
English
French
Spanish
(71) 555-5598 UK5/29/1960
8 Laura CallahanInside Sales Coordinator
English
Mandarin
(206) 555-1189 USA1/9/1958
9 Anne DodsworthSales Representative
English
Japanese
(71) 555-4444 UK1/27/1966
 

This sample is designed for a larger screen size.

On mobile, try rotating your screen, view full size, or email to another device.

jsRender is a third party templating engine which can be enabled in the igGrid. This sample demonstrates the use of the jsRender in the grid's column template. "Name" and "Birth Date" columns use helper functions to process their content while "Languages" column demonstrates the {{for ...}} iterator tag.

Code View

Copy to Clipboard
<!DOCTYPE html>
<html>
<head>
    <title></title>

    <!-- Ignite UI for jQuery Required Combined CSS Files -->
    <link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
    <link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/structure/infragistics.css" rel="stylesheet" />

    <script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>

    <!-- Ignite UI for jQuery Required Combined JavaScript Files -->
    <script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.core.js"></script>
    <script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.lob.js"></script>

    <script src="/js/external/jsrender.js" type="text/javascript"></script>
</head>
<body>

    <table id="grid12"></table>

    <!--Sample JSON Data-->
    <script src="/data-files/nw-employees.js"></script>

    <script>
        $(function () {
            var titles = ["Sales Representative", "Sales Manager", "Inside Sales Coordinator", "Vice President, Sales"];
            var countries = ["UK", "USA"];

            $.views.helpers(
            {
                toDate: function (val) {
                    return new Date(val);
                }
            });

            $.views.helpers(
            {
                toFullName: function (val) {
                    var name = val.split(',').reverse().join(" ");
                    return name;
                }
            });

            $("#grid12").igGrid({
                width: "100%",
                height: "600px",
                autoGenerateColumns: false,
                autoCommit:true,
                columns: [
                        { headerText: "Employee ID", key: "ID", dataType: "number" },
                        { headerText: "Name", key: "Name", dataType: "string", template: "{{>#view.hlp('toFullName')(Name)}}" },
                        {
                            headerText: "Image", key: "ImageUrl", dataType: "object",
                            template: "<img width='100' height='90' src={{>ImageUrl}}></img>"
                        },
                        { headerText: "Title", key: "Title", dataType: "string" },
                        {
                            headerText: "Languages", key: "Languages", dataType: "object",
                            template: "{{for Languages}}<div>{{:name}}</div>{{/for}}"
                        },
                        { headerText: "Phone", key: "Phone", dataType: "string" },
                        {
                            headerText: "Country", key: "Country", dataType: "string",
                            template: "<img width='26' height='15' src='/images/samples/nw/countries/{{>Country}}.gif'></img> <span style='display: table-cell;vertical-align: middle;'>{{>Country}}</span>"
                        },
                        {
                            headerText: "Birth Date", key: "BirthDate", dataType: "date",
                            template: "<span style='color:{{if #view.hlp('toDate')(BirthDate) > #view.hlp('toDate')('1980-01-01T00:00:00.000')}}#4573D6{{else}}#F75F4F{{/if}};'>{{>BirthDate}}</span>"
                        }
                    ],
                dataSource: northwindEmployees,
                primaryKey: "ID",
                templatingEngine: "jsrender",
                features: [
                    {
                        name: 'Responsive',
                        enableVerticalRendering: false,
                        columnSettings: [
                            {
                                columnKey: 'ID',
                                classes: 'ui-hidden-phone'
                            },
                            {
                                columnKey: 'Phone',
                                classes: 'ui-hidden-phone'
                            },
                            {
                                columnKey: 'Name',
                                classes: 'ui-hidden-phone'
                            }
                        ]
                    }
                ]
            });
        });

    </script>
</body>
</html>