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

[Solved] Styling sorted column header

1 Answer 12 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Josh
Top achievements
Rank 1
Josh asked on 20 Sep 2011, 03:38 PM
Is there a way to style a sorted column header? The ASP.NET version apparently uses the .rgSorted class, but the MVC grid doesn't seem to add a class to sorted header cells. All I can see that happens is the sort arrow span gets added on a sort. Is there any way to remedy this, or is there a setting that would solve this problem?

Thanks,
Josh C

1 Answer, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 21 Sep 2011, 09:31 AM
Hello Josh,

Here is what you can do:

.ClientEvents(ev => ev.OnDataBinding("removeSortStyles").OnDataBound("applySortStyles"))

function removeSortStyles(e)
{
    var gridElement = $(this);
    $("td", gridElement).removeClass("mySorted");
}
     
function applySortStyles(e)
{
    var gridElement = $(this);
    $("th.t-header .t-link .t-icon").filter(":visible").each(function(index, element) {
        var cellIndex = $(element).closest(".t-header")[0].cellIndex;
        // if Grid is scrollable
        $(".t-grid-content tr", gridElement).each(function(index2, element2) {
            $(element2.cells[cellIndex]).addClass("mySorted");
        });
        // else
//        $(">table tbody tr", gridElement).each(function(index2, element2) {
//            $(element2.cells[cellIndex]).addClass("mySorted");
//        });
 
    });
}

.mySorted
{
    background:#ff0;
}


The above will apply yellow background to sorted data cells. If you want to style the header cells, you should modify this jQuery selector:

$(".t-grid-content tr", gridElement)

to

$(".t-grid-content tr,.t-grid-header tr", gridElement)

and

$("td", gridElement).removeClass("mySorted");

to

$("th, td", gridElement).removeClass("mySorted");


Regards,
Dimo
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or