Getting the $page context on a kendoListView template

109 Views Asked by At

I'm using a kendoListView and I want to display only the item that satisfied my if conditional:

<div id="selectableListView" data-bind="kendoListView: { data: dataSource._kendoDataSource, template: $('#template_selectable').html(), selectable: true, change: changeMultiSelection, navigatable: true, dataBound: productsRetrieved}"> </div>

<script type="text/x-kendo-tmpl" id="template_selectable">
    #if(variableFromPageId !== Id){#
    <div class="principal">
        <div class="list-view-details">
            <div class="secction-top">
                <div class="item-name-two-lines item-name-link">
                    <a class="link"> #:Project.Utils.getDefaultName(Name)# </a>
                </div>
            </div>
            <div class="secction-center">
                <span class="item-description-two-lines">#:Project.Utils.getDefaultDescription(Description)#</span>
            </div>
        </div>
    </div>
    #}else{#
        console.log('Do nothing!');
    # }#
</script>

The problems is that variableFromPageId is located on my page context and the listview can't access to that context how can I access to the variables from the page that is calling to the kendoListView? or send the variableFromPageId as variable. I tried a many things like:

<div data-bind="if: checkId(Id)">
</div>

#console.log(ko.contextFor(this).$page.checkId('#:Id#'));#

Inside data-bind doens't work at all inside the list view it ignores all the data-bind, the second option the console log says that can't find $page of null, so how can I get the context from the page that has the KendoListView.

1

There are 1 best solutions below

0
Joe Wilson On

You must not have variableFromPageId in your data source, so your template doesn't know what it is.

You can either add that value to your existing data source by adding it to each array value, or you could pass a different data source to the Kendo template that is higher up in your model, like maybe your Knockout $root or $parent value. If you pick the latter, you will need to put your own for statement in your Kendo template to loop through the array.