Kendo Grid不可编辑单元格

时间:2014-11-17 12:53:44

标签: javascript asp.net-mvc kendo-grid

想知道是否有人可以帮助我。我有一个Kendo Grid,假设每行的每一端有2个单元格 - 这两个单元格用计算值更新。但是,我注意到我的单元格只有在我将其置于false时才会更新,因为值不会更新。请帮忙!

var ds = new kendo.data.DataSource({
                    transport: {
                        read: {
                            url: myurl,
                            dataType: "json"
                        }
                    },

                    schema: {
                        model: {
                            fields: {
                                InvestmentCode: { type: "string", editable: false, },
                                InvestmentName: { type: "string", editable: false, },
                                Units: { type: "number", editable: false, },
                                UnitPrice: { type: "number", editable: false, },
                                MarketValue: { type: "number", editable: false, },
                                AllocatedWithdraw: { type: "number", validation: { min: 0, max: 100 }, defaultValue: 0},
                                IndicativeWithdraw: { type: "number", defaultValue: "0"},
                                PostTransactionMarketValue: { type: "number", defaultValue: "0"}
                            }
                        }
                    },

                    aggregate: [
                        { field: "MarketValue", aggregate: "sum" },
                        { field: "AllocatedWithdraw", aggregate: "sum" },
                        { field: "IndicativeWithdraw", aggregate: "sum" },
                        { field: "PostTransactionMarketValue", aggregate: "sum" }
                    ],
                });

                $("#gridEditable").kendoGrid({
                    dataSource: ds,
                    maxheight: 430,
                    sortable: false,
                    columns: [
                        {
                            field: "InvestmentCode",
                            title: "Investment Code",
                            filterable: false,

                        },
                        {
                            field: "InvestmentName",
                            title: "Investment Name",
                            format: "{0:MM/dd/yyyy}"
                        },
                        {
                            field: "Units",
                            title: "Tradable Unit",
                            headerAttributes: { "class": "text-right-forced" },
                            attributes: { "class": "text-right-forced" },
                            format: "{0:#.##}",
                            template: "#= Units.toFixed(2) #",
                        },
                        {
                            field: "UnitPrice",
                            title: "Unit Price",
                            headerAttributes: { "class": "text-right-forced" },
                            attributes: { "class": "text-right-forced" },
                            format: "{0:#.####}",
                            template: "#= UnitPrice.toFixed(4) #",
                        },
                        {
                            field: "MarketValue",
                            title: "Current Market Value",
                            headerAttributes: { "class": "text-right-forced" },
                            attributes: { "class": "text-right-forced" },
                            format: "{0:c}",
                            footerTemplate: "#= kendo.toString(sum,'c') #",
                            footerAttributes: { "class": "text-right-forced" }
                        }
                        ,
                        {
                            field: "AllocatedWithdraw",
                            title: "Allocated Withdraw",
                            width: "100px",
                            format: '{0:#.##} %',
                            headerAttributes: { "class": "text-right-forced" },                           
                            attributes: { "class": "text-right-forced" },
                            footerTemplate: "#= kendo.toString(sum) #",
                            footerAttributes: { "class": "text-right-forced" }
                        }
                        ,
                        {
                            field: "IndicativeWithdraw",
                            title: "Indicative Withdraw",
                            headerAttributes: { "class": "text-right-forced" },
                            attributes: { "class": "text-right-forced" },
                            format: "{0:c}",
                            footerTemplate: "#= kendo.toString(sum,'c') #",
                            footerAttributes: { "class": "text-right-forced" }
                        },
                        {
                            field: "PostTransactionMarketValue",
                            title: "Post Transaction Market Value",
                            headerAttributes: { "class": "text-right-forced" },
                            attributes: { "class": "text-right-forced" },
                            format: "{0:c}",
                            footerTemplate: "#= kendo.toString(sum,'c') #",
                            footerAttributes: { "class": "text-right-forced" }
                        }

                    ],
                    editable: true,
                    save: function (data) {                      

                        var IndicativeWithdraw_Temp = ($("#iWithdraw").val() / 100) * data.values.AllocatedWithdraw;
                        var PostTransactionMarketValue_Temp = data.model.MarketValue - IndicativeWithdraw_Temp;

                        data.model.set("AllocatedWithdraw", data.values.AllocatedWithdraw);
                        data.model.set("PostTransactionMarketValue", PostTransactionMarketValue_Temp);
                        data.model.set("IndicativeWithdraw", IndicativeWithdraw_Temp);                          


                        this.refresh();

                    }

                });

1 个答案:

答案 0 :(得分:0)

我一周前遇到过同样的问题。似乎kendo UI认为无法更改不可编辑的字段,因此无需更新视图。

我通过在数据源中手动设置新值来解决它,方法是使用=运算符(注意:Set不会更新数据源中的字段)并通过向其添加类来更新网格单元,这样我就可以轻松找到它。

function calculateScore(e){
  var row = e.container.closest("tr")
  var item = $("#Grid").data("kendoGrid").dataItem(row);
  item.A1A4 = item.A1 + item.A4;
  row.find("td.smso_A1A4").text((item.A1 + item.A4).toString());
}