Hi,
I've got an issue when rebinding the datagrid and aggregates.
The following javascript creates the grid. Columns of the reports are unkown, the data I'm getting contains an array with the column list, and an array with the actual data.
I found this problem when executing a report that has left joins, so if there is no data, I still get rows, but no values to the columns I want to aggregate.
If the first time the report is generated has no data, the aggregates are not created the second time round, even if I do have data.
But if the first time the data loads I have data the aggregates are shown. Then if the second time I don't have data, I receive the following error "Uncaught TypeError: undefined has no properties" at "grid.setDataSource(newDs);"
I've got an issue when rebinding the datagrid and aggregates.
The following javascript creates the grid. Columns of the reports are unkown, the data I'm getting contains an array with the column list, and an array with the actual data.
I found this problem when executing a report that has left joins, so if there is no data, I still get rows, but no values to the columns I want to aggregate.
If the first time the report is generated has no data, the aggregates are not created the second time round, even if I do have data.
But if the first time the data loads I have data the aggregates are shown. Then if the second time I don't have data, I receive the following error "Uncaught TypeError: undefined has no properties" at "grid.setDataSource(newDs);"
var
reports = {
getGridColumns:
function
(columns) {
var
columnArray = [];
$.each(columns,
function
(i, c) {
var
column = { field: c.Name, title: c.Title, width: 150 };
if
(c.Format) {
column.format =
'{0:'
+ c.Format +
'}'
;
}
if
(c.ShowTotals) {
column.footerTemplate =
"#=kendo.toString(sum,'"
+ c.Format +
"')#"
;
}
columnArray.push(column);
});
return
columnArray;
},
getGridAggregates:
function
(columns) {
var
columnArray = [];
$.each(columns,
function
(i, c) {
if
(c.ShowTotals) {
columnArray.push({ field: c.Name, aggregate:
"sum"
});
}
});
if
(columnArray.length == 0) { columnArray = undefined; }
return
columnArray;
},
bindKendoGrid:
function
() {
$.ajax({
type:
'POST'
,
url:
'/Reports/GetReportData'
,
data: reports.getReportParams(),
success:
function
(data) {
if
(data && data.Data && data.Data.length > 0) {
if
(!$(
'#report-grid'
).data(
'kendoGrid'
)) {
$(
'#report-grid'
).kendoGrid({
dataSource: {
data: eval(data.Data),
pageSize: 15,
aggregate: reports.getGridAggregates(data.Columns)
},
columns: reports.getGridColumns(data.Columns),
scrollable:
true
,
sortable:
true
,
filterable:
true
,
pageable: {
input:
true
,
numeric:
false
}
});
}
else
{
var
grid = $(
'#report-grid'
).data(
'kendoGrid'
);
var
newDs =
new
kendo.data.DataSource({
data: eval(data.Data),
pageSize: 15,
aggregate: reports.getGridAggregates(data.Columns)
});
grid.setDataSource(newDs);
}
$(
'#report-grid'
).css(
'display'
,
'block'
);
$(
'#report-container #report-export'
).show();
}
else
{
$(
'#no-data'
).css(
'display'
,
'block'
);
}
$(
'#report-container'
).css({ position:
''
, width:
''
, height:
''
});
kendo.ui.progress($(
"#report-container"
),
false
)
$(
'#btnReportRefresh'
).removeAttr(
'disabled'
).removeClass(
'k-state-disabled'
);
},
error:
function
(data) {
kendo.ui.progress($(
"#report-container"
),
false
)
$(
'#btnReportRefresh'
).removeAttr(
'disabled'
).removeClass(
'k-state-disabled'
);
$(
'#no-data'
).css(
'display'
,
'block'
);
kendo.ui.progress($(
"#commissions-dashboard"
),
false
);
}
});
}
}