Kendo UI Grid,添加列和列总和值

时间:2013-11-12 22:14:05

标签: javascript datasource kendo-grid

我正在使用Kendo Grid工具。 我有一个数据源,其中包含一个对象的值,在这个对象中存在另一个。就像两个数组,一个在另一个数组内。

$("#PedidoConsolidadoGrid").kendoGrid({
    dataSource: {
        data: mData,
        schema: {
            model: { // define the model of the data source. Required for validation and property types.
                id: "CodigoArticulo",
                fields: {
                    //CodigoPedido: { editable: false },
                    CodigoArticulo: { editable: false },
                    FechaPedido: { editable: false },
                    CantidadExistencias: { editable: false },
                    DescripcionArticulo: { editable: false },
                    CantidadConsolidar: {
                        editable: true, 
                        type: "number", 
                        validation: { required: true, min: 0, max: 9999 },
                    },
                }
            }
        },
        pageSize: 11
    },
    scrollable: true,
    pageable: true,
    editable: {
        mode: "inline", // mode can be incell/inline/popup with Q1 '12 Beta Release of Kendo UI
        confirmation: false // the confirmation message for destroy command
    }, // enable editing
    selectable: "single",
    pageable: {
        numeric: true,
        previousNext: true,
        refresh: true,
        buttonCount: 5,
        messages: {
            display: "Mostrando {0}-{1} de {2}",
            empty: "No hay datos para mostrar",
            page: "Enter page",
            of: "de {0}",
            itemsPerPage: "Pedidos por página",
            first: "Primera página",
            last: "Última página",
            next: "Siguiente",
            previous: "Anterior",
            refresh: "Refrescar"
        }
     },
     columns: [
         //{ field: "CodigoPedido", title: "Código del Pedido", width: "150px" },
         { field: "CodigoArticulo", title: mData[0].CodigoArticulo , width: "150px" },
         { field: "DescripcionArticulo", title: "Articulo", width: "200px" },
         { field: "FechaPedido", title: "Fecha Pedido", width: "150px", template: '#= kendo.toString( toDate(FechaPedido), "dd/MM/yyyy" ) #' },
         { field: "CantidadConsolidar", title: "Total Pedido", width: "120px", },
         { field: "CantidadExistencias", title: "Total Existencia", width: "120px" },
         { command: "edit", text: "Editar"}
     ],
});

如何为数组中的数据创建另一个数组? 以及如何对列进行求和并在网格的另一列中显示总数。

1 个答案:

答案 0 :(得分:0)

您应该检查计算出的属性,在这种情况下,CantidadConsolidar可能是一个计算字段。

dataSource = new kendo.data.DataSource({
data: [
  { first: "John", last: "Doe" }, 
  { first: "Jane", last: "Doe" }
],
schema: {
  model: {
    // Calculated field
    fullName: function() {
      return this.get("first") + " " + this.get("last");
    }
    fields:{
        ...
    },
  }
}

});

另外,请检查DataSource Aggregates以显示网格中某一列的值之和。