【问题标题】:How to bind columns definition dynamically on KendoUI如何在 Kendo UI 上动态绑定列定义
【发布时间】:2014-06-03 08:41:25
【问题描述】:

我需要对 kendoui 上网格的列字段进行动态绑定。

<table    id="checkout-grid"
                class="k-grid"
                data-role="grid"
                data-bind="source: items"
                data-row-template="checkout-form-item-template"
                data-scrollable="false"
                data-columns="[
                        { title: 'Name', width: '300px'},
                        'Description',
                        { title: 'Price', width: '50px' },
                        { title: 'Quantity', width: '50px' },
                        { title: 'Total', width: '100px' }
                    ]">
        </table>

问题是我需要设置不同语言的列标题。

如何在不使用对象上的 javascript kendoGrid 方法的情况下对该定义进行绑定。

我尝试从 viewmodel 绑定 data-colums 值,但它抛出一个不支持绑定异常,即使使用 attr 值也是如此。

如何执行该字段的动态绑定?

【问题讨论】:

  • 当您需要不同语言的列时,也许您可​​以使用 Kendo Grid 列方法来设置新的列集? var grid = $("#checkout-grid").data("kendoGrid"); grid.columns = // 一组新列

标签: javascript kendo-ui kendo-grid


【解决方案1】:

首先,我发现您的 Grid 定义存在问题,您说的是 title 而不是 field

回答您的问题并知道您不想动态生成columns.definition,我建议您将其定义为:

<table id="checkout-grid"
    class="k-grid"
    data-role="grid"
    data-bind="source: items"
    data-scrollable="false"
    data-columns="[
        { field: 'Name', width: '300px'},
        'Description',
        { field: 'Price', width: '50px' },
        { field: 'Quantity', width: '50px' },
        { field: 'Total', width: '100px' }
        ]">
    <thead>
        <td>Nombre</td>
        <td>Descripción</td>
        <td>Precio</td>
        <td>Cantidad</td>
        <td>Total</td>
    </thead>
</table>

即,添加带有本地化的thead 定义。但很明显,如果你的服务器可以做到这一点,也可以生成类似的东西:

<table id="checkout-grid"
    class="k-grid"
    data-role="grid"
    data-bind="source: items"
    data-scrollable="false"
    data-columns="[
        { field: 'Name', title: 'Nombre', width: '300px'},
        { field: 'Description', title: 'Descripción' },
        { field: 'Price', width: '50px', title: 'Precio' },
        { field: 'Quantity', width: '50px', title: 'Cantidad' },
        { field: 'Total', width: '100px', title: 'Total' }
    ]"
>

【讨论】:

  • 对不起,这不起作用。我正在与水疗中心合作。我尝试绑定重写的thead字段的html但不起作用。我现在将尝试创建一个自定义绑定属性来分配该属性。
猜你喜欢
  • 1970-01-01
  • 2013-12-01
  • 1970-01-01
  • 2014-01-27
  • 1970-01-01
  • 2016-12-15
  • 1970-01-01
  • 2013-02-12
  • 1970-01-01
相关资源
最近更新 更多