Search code examples
knockout.jswijmo

Wijmo grid and knockout observableArray bound to data option not working for me


The wijmo grid setup to get its data from a knockout observableArray in the following fiddle http://jsfiddle.net/t316/K3GMR/7/ is not initializing itself properly, i.e. you see no grid.

This is happening because of an error:

"Uncaught TypeError: Object function d(){if(0<arguments.length){if(!d.equalityComparer||!d.equalityComparer(c,arguments[0]))d.H(),c=arguments[0],d.G();return this}b.r.Wa(d);return c} has no method 'load' "

Wijmo grid is supposed to be able be bound to a knockout observableArray in the manner I am trying, is it not? Why is the grid not initializing properly and not showing the small sample data?


Solution

  • Here is the correct way of binding a wijgrid with KO observable array. The following code goes into the script section:

        var viewModel = {
            data: ko.observableArray([
              { "Name": "a" },
              { "Name": "b" }
            ])
        };
    
        //Bind ViewModel
        $(document).ready(function () {
            ko.applyBindings(viewModel);
        });
    

    The HTML table can be defined like below:

    <table id="dataGrid" data-bind="wijgrid: { data: data, columns : [ { headerText : 'Name'}],
        ensureControl : true} ">
    </table>
    

    Hope this helps..