【问题标题】:Kendo UI Grid - Filter Integer Column showing as decimalKendo UI Grid - 过滤整数列显示为十进制
【发布时间】:2015-12-28 18:45:19
【问题描述】:

我正在使用 Kendo UI (2015.3.930) 网格控件,并且我在网格过滤器行中有一个整数文本框,当我应用过滤器时它始终为十进制。

这是我的代码:

@(Html.Kendo().Grid((IEnumerable<UiController.Lot>)Model.Lots)
   .Name("Grid")
   .Columns(columns =>
       {
          columns.Bound(c => c.LotNumber).Title("Lot No")
               .Filterable(ftb =>ftb.ItemTemplate("NumericFilter"));
          columns.Bound(c => c.BranchName).Title("Branch Name");
       })
  .HtmlAttributes(new { style = "height: 530px;" })
  .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
  .DataSource(dataSource => dataSource
       .Server()
       .Model(model => { model.Id(p => p.Id); })
    )
)

我的脚本部分显示:

<script>
function NumericFilter(args) {
    args.element.kendoNumericTextBox({
        "spinners" : false,
        "format": "n0",
        "decimals": 0,
    });
}

对于整数值 10,在应用过滤器后显示“10.00”。有没有办法显示没有小数部分的值。

谢谢,

【问题讨论】:

    标签: user-interface kendo-ui grid


    【解决方案1】:

    我准备了Dojo example 只是为了表明这是可能的。

    我没有 MVC 包装器,但看起来,如果你对代码做一些小的修改,它就会起作用:

    1] 将 Filterable 中的 ItemTemplate 更改为 UI

    columns.Bound(c => c.LotNumber).Title("Lot No").Filterable(ftb => ftb.UI("NumericFilter"));
    

    2] 然后,您应该能够通过小(选择器)修改显示的语法获得想要的行为

    <script>
    function NumericFilter(args) {
    $(args).kendoNumericTextBox({
        "spinners" : false,
        "format": "n0",
        "decimals": 0,
    });
    }
    

    【讨论】:

      【解决方案2】:

      要自定义此字段,您需要使用 cell.template,请更新您的代码如下:

      columns.Bound(c => c.LotNumber)
          .Title("Lot No")
          .Filterable(ftb => ftb.Cell(c => c.Template("NumericFilter")));
      

      【讨论】:

      • 伟大的@Luis,请标记此答案以帮助其他用户解决此问题。
      • 最好在你的 js 函数中使用 format: "g" 因为当文本框失去焦点时,它会显示一个像 12,345 这样的数字。
      猜你喜欢
      • 2013-03-13
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-10-28
      • 2016-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多