This is a migrated thread and some comments may be shown as answers.

Incorrect order for Year and Month Columns

16 Answers 318 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Veteran
Lee asked on 25 Mar 2018, 07:45 AM

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

Sort by
0
Viktor Tachev
Telerik team
answered on 27 Mar 2018, 10:51 AM
Hello Lee,

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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Lee
Top achievements
Rank 1
Veteran
answered on 27 Mar 2018, 08:57 PM

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.

0
Viktor Tachev
Telerik team
answered on 29 Mar 2018, 01:01 PM
Hi 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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Lee
Top achievements
Rank 1
Veteran
answered on 31 Mar 2018, 02:02 AM

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.

 

 

0
Konstantin Dikov
Telerik team
answered on 03 Apr 2018, 12:45 PM
Hello 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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Lee
Top achievements
Rank 1
Veteran
answered on 04 Apr 2018, 07:11 AM

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.

0
Lee
Top achievements
Rank 1
Veteran
answered on 04 Apr 2018, 07:18 AM
Also as an FYI the Ajax is returning correctly see attached
0
Konstantin Dikov
Telerik team
answered on 06 Apr 2018, 05:14 AM
Hi Lee,

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
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Lee
Top achievements
Rank 1
Veteran
answered on 06 Apr 2018, 05:23 AM
Thanks Konstantin, that's disappointing. Do you have any recommendations on setting up OLAP binding? I'm currently using Code-First Entity Framework.
0
Konstantin Dikov
Telerik team
answered on 09 Apr 2018, 01:00 PM
Hello Lee,

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:
Hope this helps.


Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Heiko
Top achievements
Rank 1
Iron
Veteran
answered on 18 May 2020, 08:02 AM
Indeed very disappointing. The PivotGrid in ASP.NET (MVC and Core) seems to be a little stepchild for Telerik and is only working up to a point if I use an OLAP cube. I am very surprised because the know-how is there, for example with the PivotGrid in WPF which works really good without any OLAP cube. Any plans to enhance this in ASP.NET in the near future?.
0
Alex Hajigeorgieva
Telerik team
answered on 19 May 2020, 02:12 PM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Heiko
Top achievements
Rank 1
Iron
Veteran
answered on 21 May 2020, 02:16 PM

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

0
Alex Hajigeorgieva
Telerik team
answered on 25 May 2020, 10:23 AM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Alex Hajigeorgieva
Telerik team
answered on 18 Nov 2020, 10:59 AM

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/.

0
Heiko
Top achievements
Rank 1
Iron
Veteran
answered on 23 Nov 2020, 02:04 PM
Thanks a lot and "thumbs up"! :-)
Tags
PivotGrid
Asked by
Lee
Top achievements
Rank 1
Veteran
Answers by
Viktor Tachev
Telerik team
Lee
Top achievements
Rank 1
Veteran
Konstantin Dikov
Telerik team
Heiko
Top achievements
Rank 1
Iron
Veteran
Alex Hajigeorgieva
Telerik team
Share this question
or