Hi,
I have two columns Year and Month, these don't appear in order.
For example they display as Year: 2017, 2018, 2020, 2019. Then the Month: February, January, March, July eyc.
How can i sort these to appear in order?
Thanks,
Lee.
16 Answers, 1 is accepted
The behavior you describe could be observed if the underlying fields are type string. In that case the sorting will be applied based on the text values that are displayed. In order to have sort order work as expected please ensure that the underlying field is a DateTime. This would sort the values by the date and the order would be as expected.
In case the behavior persists please send us a runnable project or a dojo sample where it is replicated so we can examine it locally.
Regards,
Viktor Tachev
Progress Telerik
Hi Victor,
Thanks for your reply.
I do have a DateTime filed, but i'm unsure how to get just the month or year to display.
Here's my class:
public
class
SaleView
{
public
DateTime ForecastCloseDate {
get
;
set
; }
public
string
ForecastCloseDateYear {
get
;
set
; }
public
string
ForecastCloseDateMonth {
get
;
set
; }
}
Here's the columns part from the PivotGrid:
.Columns(columns =>
{
columns.Add(
"ForecastCloseDateYear"
).Expand(
true
);
columns.Add(
"ForecastCloseDateMonth"
).Expand(
true
);
})
As you can see i'm using the string versions of the ForecastCloseDate as i'm not sure how to use ForecastClaseDate and display just the Month and Year.
Thanks,
Lee.
I have examined the snippets and it seems that ForecastCloseDateYear and ForecastCloseDateMonth fields are defined as string. If you would like the fields to be sorted as dates please make sure that they are defined as DateTime and then format the values as described in the article below:
Regards,
Viktor Tachev
Progress Telerik
Thanks Viktor.
I've tried modifying the sample you provide and made ForecastCloseDateYear and ForecastCloseDateMonth Date object.
I'm now correctly getting the Year and Month from the DateTime object using the ColumnHeaderTemplateId, but they are not grouping together (attached image)
My Header Template:
<
script
id
=
"headerTemplate"
type
=
"text/x-kendo-tmpl"
>
# if (!member.children.length) { #
# if (member.name.indexOf("ForecastCloseDateYear") === 0 && member.name !== "ForecastCloseDateYear") { #
#: kendo.toString(new Date(member.caption), "yyyy") #
# } else if (member.name.indexOf("ForecastCloseDateMonth") === 0 && member.name !== "ForecastCloseDateMonth") { #
#: kendo.toString(new Date(member.caption), "MMMM") #
# } #
# } else { #
#: member.caption #
# } #
</
script
>
My PivotGrid Columns:
.Columns(columns =>
{
columns.Add(
"ForecastCloseDateYear"
).Expand(
true
);
columns.Add(
"ForecastCloseDateMonth"
).Expand(
true
);
})
Many thanks,
Lee.
You could consider storing the "Year" as numeric value, so that the same value could be used for all records for the same year. The other solution would be to ensure that each Date object for each specific year is the same.
Regards,
Konstantin Dikov
Progress Telerik
Ok, so i've changed them to int's and they still display wrong see attached photo.
Here's my class:
public
class
SaleView
{
[Key]
public
Guid Id {
get
;
set
; }
public
string
Jobnumber {
get
;
set
; }
public
string
Tracking {
get
;
set
; }
public
string
TaskSalesPerson {
get
;
set
; }
public
string
ClientName {
get
;
set
; }
public
string
Task {
get
;
set
; }
public
string
TaskType {
get
;
set
; }
public
DateTime QuoteCreatedDate {
get
;
set
; }
public
DateTime NextFollowUp {
get
;
set
; }
public
string
Status {
get
;
set
; }
public
string
LeadType {
get
;
set
; }
public
string
SalesPhase {
get
;
set
; }
public
double
ForecastPercent {
get
;
set
; }
public
DateTime ForecastCloseDate {
get
;
set
; }
// Calculated from ForecastCloseDate = Used for Pivot (need to be separate instances)
public
int
ForecastCloseDateYear {
get
;
set
; }
public
int
ForecastCloseDateMonth {
get
;
set
; }
public
double
Estimated {
get
;
set
; }
// Estimated Value
public
double
QuoteTotalHours {
get
;
set
; }
// Calculated
public
double
ForecastSell {
get
;
set
; }
public
double
QuoteTotalEx {
get
;
set
; }
// Quote Total Value
public
DateTime ProjectStartDate {
get
;
set
; }
public
int
ProjectDurationMonths {
get
;
set
; }
}
Here's my Razor widget:
@(
Html.Kendo().PivotGrid<SaleView>()
//.ColumnHeaderTemplateId("headerTemplate")
.Name(
"pivotgrid"
)
.Excel(excel => excel
.FileName(
"Sales - Overall.xlsx"
)
.Filterable(
true
)
.ProxyURL(Url.Action(
"ExcelExportSave"
,
"Kendo"
))
)
.ColumnWidth(200)
.Height(580)
.HtmlAttributes(
new
{ @
class
=
"hidden-on-narrow"
})
.Filterable(
true
)
//.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.Transport(transport => transport.Read(
"SaleListAjax"
,
"Kendo"
,
new
{ AssignedTo = ViewBag.Name }))
.Schema(schema => schema
.Cube(cube => cube
.Dimensions(dimensions =>
{
//dimensions.Add(model => model.LeadType).Caption("Lead Types");
//dimensions.Add(model => model.TaskSalesPerson).Caption("Sales Persons");
//dimensions.Add(model => model.SalesPhase).Caption("Sales Phase");
})
.Measures(measures => measures.Add(
"Forecast Sell"
).Field(model => model.ForecastSell).AggregateName(
"sum"
).Format(
"{0:C}"
))
))
.Columns(columns =>
{
columns.Add(
"ForecastCloseDateYear"
).Expand(
true
);
columns.Add(
"ForecastCloseDateMonth"
).Expand(
true
);
})
.Rows(rows =>
{
rows.Add(
"LeadType"
).Expand(
true
);
rows.Add(
"TaskSalesPerson"
).Expand(
true
);
rows.Add(
"SalesPhase"
).Expand(
true
);
})
.Measures(measures => measures.Values(
"Forecast Sell"
))
.Events(e =>
{
e.Error(
"onError"
);
e.RequestEnd(
"onRequestEnd"
);
})
)
)
Finally here's my Controller:
public
ActionResult SaleListAjax([DataSourceRequest] DataSourceRequest request,
string
assignedTo =
null
)
{
var sales = AroFloService.GetQueryableSaleView();
if
(assignedTo !=
null
)
sales = sales.Where(x => x.TaskSalesPerson.Equals(assignedTo));
return
Json(sales.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
I just can't figure out why they won't display in order.
After further tests and consulting with our developers team it seems that with binding the PivotGrid to flat data it will not be possible to have initial sort over data as per your requirements and I apologize for the misleading information in the previous posts. Such sorting will be possible with OLAP binding only:
Once again, please excuse us for any inconvenience caused by the information in the previous posts.
Regards,
Konstantin Dikov
Progress Telerik
You could take a look at the following Kendo UI PivotGrid help topics for general information about OLAP cube. Note that the only difference with the MVC helper is the syntax of the PivotGrid configuration:
- https://docs.telerik.com/kendo-ui/controls/data-management/pivotgrid/fundamentals
- https://docs.telerik.com/kendo-ui/controls/data-management/pivotgrid/olap-cube-setup
Hope this helps.
Regards,
Konstantin Dikov
Progress Telerik
Hello, Heiko,
I am sorry that you are disappointed in the current situation with the Kendo UI PivotGrid. You are absolutely right about the existing solutions we have in the company and we have addressed this exact point in the team. There is a scheduled upcoming internal task that will explore this in depth.
The ongoing care to our children (components) in Telerik is tightly bound to the demand of our clients and their business needs. We gauge that via a number of different channels and one of them is our Feedback portal which features this request and I have already voted on your behalf:
https://feedback.telerik.com/kendo-jquery-ui/1360085-add-sorting-to-kendo-ui-pivotgrid
However, I wish to assure you that the PivotGrid is not a stepchild, it just has been one of the less popular kids on the block. The good news is that this has changed recently and this is why we have an internal task to review the PivotGrid engine I mentioned earlier. Hopefully, in the following quarter there might be some improvements in that regard.
As business needs change, so do our priorities so it is best to keep an eye out on our road map:
https://www.telerik.com/support/whats-new/kendo-ui
Regards,
Alex Hajigeorgieva
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hello Alex,
it is good to see that someone listens at Telerik - thanks a lot. But it has something of a self-fulfilling prophecy. Maybe it's not so popular because it doesn't offer many features, so it won't be developed further, and that's why it remains unpopular. But I understand that thoughts are being given, and I am very excited to see how it goes on.
Regards
Heiko
Hello, Heiko,
Thank you very much for your feedback and sharing your point of view with us, it comes at a perfect time.
I am also excited about what will become of it and look forward to seeing the improvements that await.
Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hi, Heiko & Lee,
Just a quick note to let you know that we have implemented columns and rows headers sorting in 2020 R3:
https://feedback.telerik.com/kendo-jquery-ui/1360085-add-sorting-to-kendo-ui-pivotgrid
Next up in the near future we will look into sorting of the aggregates values.
Regards,
Alex Hajigeorgieva
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.