Filtering source in a Kendo Template

不羁岁月 提交于 2019-11-30 10:00:34

问题


I have following Kendo template and MVVM binding. Source for this is template is viewModel that has employees inside it. The employees collection has 3 records in it. I need to display only those records for which the IsSelected property is true.

<!----Kendo Templates-->
<script id="row-template" type="text/x-kendo-template">
      <tr>
            <td data-bind="text: name"></td>
            <td data-bind="text: age"></td>
      </tr>
</script>


employees: [
                    { name: "Lijo", age: "28", IsSelected: true },
                    { name: "Binu", age: "33", IsSelected: false },
                    { name: "Kiran", age: "29", IsSelected: false }
                   ]

QUESTION

How can we specify this filtering inside the template?

CODE

<head>
    <title>Template Filtering</title>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
    <!----Kendo Templates-->
    <script id="row-template" type="text/x-kendo-template">
          <tr>
                <td data-bind="text: name"></td>
                <td data-bind="text: age"></td>
          </tr>
    </script>
    <!--MVVM Wiring using Kendo Binding-->
    <script type="text/javascript">

        $(document).ready(function () {
            kendo.bind($("body"), viewModel);
        });

    </script>
    <script type="text/javascript">
        var viewModel = kendo.observable({

            employees: [
                        { name: "Lijo", age: "28", IsSelected: true },
                        { name: "Binu", age: "33", IsSelected: false },
                        { name: "Kiran", age: "29", IsSelected: true }
                       ]
        });

    </script>

    <style>
        table, th, td
        {
            border: 1px solid black;
        }
    </style>

</head>
<body>
    <table id="resultTable">
        <tbody data-template="row-template" data-bind="source: employees">
        </tbody>
    </table>
</body>

REFERENCES

  1. KendoUI Check Boxes in a Grid: how to and some tips and tricks
  2. Filter kendo ui grid with filed type object
  3. Filter Array|Object
  4. MVVM / Source and template binding
  5. how to run a function inside a template

回答1:


Use the visible binding...

Use visible binding

<script id="row-template" type="text/x-kendo-template">
    <tr data-bind="visible: IsSelected">
        <td data-bind="text: name"></td>
        <td data-bind="text: age"></td>
    </tr>
</script>


来源:https://stackoverflow.com/questions/22072180/filtering-source-in-a-kendo-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!