4

I'm currently looking at koGrid to render dynamic data grids, and I need some customization.

For example, I'd like to show and hide columns without making use of the default columns menu.

This is the HTML output of that columns menu:

<div data-bind="visible: showColumnMenu">
    <span class="kgMenuText">Choose Columns:</span>
    <ul class="kgColList" data-bind="foreach: nonAggColumns">
        <li class="kgColListItem">...</li>
    </ul>
</div>

As you can see, the foreach binding makes use of the nonAggColumns property. If you'd look at the koGrid library, this property is defined on window.kg.Grid. I'd like to be able to access this property (and others of the kg.Grid) from outside of the koGrid's context.

Has anyone got an idea on how to achieve this? Any help greatly appreciated!

thomaux
  • 19,133
  • 10
  • 76
  • 103

1 Answers1

4

You can use ko.dataFor(elem), where elem is the child div of your koGrid root element, that's the element on which koGrid does ko.applyBindings with the main Grid object. As far as I know this is not documented and could change with any new release (this works at least with version 2.1). And also there might be a better/safer way I'm unaware of.

See example jsfiddle: http://jsfiddle.net/antishok/23D7C/11/

antishok
  • 2,910
  • 16
  • 21