我有一个调用ajax函数来填充网格数据源的Combobox事件。 我可以看到我的网格正确填充但总和Sum显示为0。 我该怎么办?
AJAX致电
$.ajax({
url: '@Url.Action("CreaGrid3", "Sales")',
dataType: "json",
contentType: "application/json; charset=utf-8",
data: { bra: brand, mod: model, prj: project, ver: version, rel: release },
success: function (result) {
var grid = $("#Grid3").data("kendoGrid");
var dataSource = new kendo.data.DataSource({
data: result.Data
});
grid.setDataSource(dataSource);
grid.dataSource.read();
}
我的观点:
@(Html.Kendo().Grid<IndSudUI.Models.TabTemp3>()
.Name("Grid3")
.Columns(columns =>
{
columns.Bound(e => e.DESCRIZIONE);
columns.Bound(e => e.Totale)
.Format("{0:C3}")
.ClientFooterTemplate("Sum: #=sum#");
})
.Pageable()
.Sortable()
.Scrollable()
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Aggregates(a =>
{
a.Add(p => p.Totale).Sum();
})
.ServerOperation(false)
)
.Events(events => events.DataBound("onDataBound5"))
)
这是我的控制器
我删除了一些不相关的代码部分
public JsonResult CreaGrid3([DataSourceRequest] DataSourceRequest request, string bra, string mod, string prj, string ver, string rel)
{
if (!String.IsNullOrEmpty(bra))
bra = bra.Trim();
if (!String.IsNullOrEmpty(mod))
mod = mod.Trim();
if (!String.IsNullOrEmpty(prj))
prj = prj.Trim();
if (!String.IsNullOrEmpty(ver))
ver = ver.Trim();
if (!String.IsNullOrEmpty(rel))
rel = Convert.ToDateTime(rel.Trim()).ToString("yyyyMMdd");
try
{
List<TabTemp3> Listed = new List<TabTemp3>();
var connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
DataTable dt = new DataTable();
string sqlcmd = "SELECT l.DESCRIZIONE, CASE WHEN m.PezziTurnoStd=0 THEN 0 ELSE (8 / CONVERT(decimal, m.PezziTurnoStd)) * pr.CostoOraDir * m.PersonaleDirettoStd END Totale FROM ";
sqlcmd = sqlcmd + "AHE.dbo.Inds0DbParArt AS m INNER JOIN ";
//... ETC ...
using (var dataAdapter = new SqlDataAdapter(sqlcmd, connection))
{
dataAdapter.Fill(dt);
}
foreach (DataRow row in dt.Rows)
{
Listed.Add(new TabTemp3
{
DESCRIZIONE = row["DESCRIZIONE"].ToString(),
Totale = (decimal)(row["Totale"])
});
}
var temp = Listed.AsEnumerable<TabTemp3>();
return Json(temp.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show("" + e);
}
return null;
}