MVC5 Classic
Load Data into the Grid

You can easily load data into the wijgrid widget from several different data sources. For example, a DOM table, array, hash, or a remote data source. See the grid > DataSources sample of the MVC Control Explorer live demo at http://demo.componentone.com/ASPNET/MVCExplorer/grid/DataSources for an example.

Complete the following steps:

  1. Create a new C1 ASP.NET MVC 5 Web Application (see Creating an MVC Classic Project).
  2. Navigate to the Solution Explorer, expand the Shared folder inside the Views folder, and double-click _Layout to open the file.
  3. Check the dependencies to make sure the project is referencing the latest version of Wijmo. These should be placed within the <head> tags of the page. You can find the latest version of the Wijmo dependencies at http://wijmo.com/downloads/cdn/.
  4. Add the following markup within the <body> tags of the page, just after @RenderBody():
    <div class="main demo">
        <p>DOM table:</p>
        <table id="demo-dom">
            <thead>
                <tr>
                    <th>ID</th><th>Company</th><th>Name</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>ANATR</td><td>Ana Trujillo Emparedados y helados</td><td>Ana Trujillo</td>
                </tr>
                <tr>
                    <td>ANTON</td><td>Antonio Moreno Taqueria</td><td>Antonio Moreno</td>
                </tr>
                <tr>
                    <td>AROUT</td><td>Around the Horn</td><td>Thomas Hardy</td>
                </tr>
                <tr>
                    <td>BERGS</td><td>Berglunds snabbkop</td><td>Christina Berglund</td>
                </tr>
            </tbody>
        </table>
        <p>Array:</p>
        <table id="demo-array">
        </table>
        <p>Hash:</p>
        <table id="demo-hash">
        </table>
        <p>Remote:</p>
        <table id="demo-remote">
        </table>
    </div>
    

    This markup will add content for four tables. Each will be used to create a grid.

  5. After the closing </div> tag you added in the previous step, enter the following jQuery script to initialize the wijgrid widgets:
     <script id="scriptInit" type="text/javascript">
            $(document).ready(function () {
                // dom
                $("#demo-dom").wijgrid();
                // array
                $("#demo-array").wijgrid({
                    data: [
                    ["ANATR", "Ana Trujillo Emparedados y helados", "Ana Trujillo"],
                    ["ANTON", "Antonio Moreno Taqueria", "Antonio Moreno"],
                    ["AROUT", "Around the Horn", "Thomas Hardy"],
                    ["BERGS", "Berglunds snabbkop", "Christina Berglund"]
                  ],
                    columns: [
                     { headerText: "ID" }, { headerText: "Company" }, { headerText: "Name" }
                  ]
                });
                // hash
                $("#demo-hash").wijgrid({
                    data: [
                    { ID: "ANATR", Company: "Ana Trujillo Emparedados y helados", Name: "Ana Trujillo" },
                    { ID: "ANTON", Company: "Antonio Moreno Taqueria", Name: "Antonio Moreno" },
                    { ID: "AROUT", Company: "Around the Horn", Name: "Thomas Hardy" },
                    { ID: "BERGS", Company: "Berglunds snabbkop", Name: "Christina Berglund" }
                  ]
                });
                // remote
                $("#demo-remote").wijgrid({
                    data: new wijdatasource({
                        proxy: new wijhttpproxy({
                            url: "http://ws.geonames.org/searchJSON",
                            dataType: "jsonp",
                            data: {
                                featureClass: "P",
                                style: "full",
                                maxRows: 5,
                                name_startsWith: "ab"
                            },
                            key: "geonames"
                        }),
                        reader: new wijarrayreader([
                         { name: "label", mapping: function (item) { return item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName } },
                         { name: "name", mapping: "name" },
                         { name: "countryCode", mapping: "countryCode" },
                         { name: "continentCode", mapping: "continentCode" }
                      ])
                    })
                });
            });
    </script>
    

    This will setup each grid's data source.

What You've Accomplished

Press F5 to run the application, observe that each grid widget is linked to a different type of data source. These include a DOM table, array, hash, and a remote data source.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum |  Documentation Feedback