Skip to content

Commit e61c097

Browse files
committed
Sync with Kendo UI Professional
1 parent 92b9b50 commit e61c097

File tree

8 files changed

+161
-8
lines changed

8 files changed

+161
-8
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
title: Customizing the Grid Column Sorting Icons
3+
description: An example on how to change the default column sorting icons when using the Telerik UI for {{ site.framework }} Grid.
4+
type: how-to
5+
page_title: Customizing the Grid Column Sorting Icons
6+
slug: grid-custom-sorting-icons
7+
tags: grid, sorting, icons, columns, header, template
8+
res_type: kb
9+
---
10+
11+
## Environment
12+
13+
<table>
14+
<tr>
15+
<td>Product</td>
16+
<td>{{ site.product }} Grid</td>
17+
</tr>
18+
<tr>
19+
<td>Progress {{ site.product }} version</td>
20+
<td>Created with the 2023.3.1010 version</td>
21+
</tr>
22+
</table>
23+
24+
## Description
25+
How can I change the default sorting icons of the Grid columns?
26+
27+
## Solution
28+
To set custom ascending and descending sorting icons when a specified Grid column is sorted and display a double arrow icon when the column is not sorted, follow these steps:
29+
30+
1. Add the following CSS style to hide the default sorting icons:
31+
```css
32+
#grid .k-grid-header .k-cell-inner .k-link .k-sort-icon {
33+
display: none;
34+
}
35+
```
36+
37+
2. Handle the `DataBound` event of the Grid that triggers each time a specified column is sorted (the sorting data operation is performed on the server (`ServerOperation(true)`).
38+
```HtmlHelper
39+
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
40+
.Name("grid")
41+
.Sortable(sortable => sortable
42+
.AllowUnsort(true)
43+
.SortMode(GridSortMode.Mixed)
44+
.ShowIndexes(true))
45+
.Events(ev => ev.DataBound("onDataBound"))
46+
// other grid configuration
47+
)
48+
```
49+
{% if site.core %}
50+
```TagHelper
51+
@addTagHelper *, Kendo.Mvc
52+
53+
<kendo-grid name="grid" on-data-bound="onDataBound">
54+
<sortable enabled="true" allow-unsort="true" mode="mixed" show-indexes="true" />
55+
<!-- Other configuration -->
56+
</kendo-grid>
57+
```
58+
{% endif %}
59+
60+
3. Within the `DataBound` event handler, define the desired SVG icons as explained in the [SVG Icons section in the documentation](https://docs.telerik.com/{{ site.platform }}/styles-and-layout/sass-themes/svg-icons#setting-svg-icons-from-client). Then, access the currently sorted fields through the [`sort()`](https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/methods/sort) method of the DataSource and append the respective icon (ascending or descending).
61+
62+
```javascript
63+
<script>
64+
function onDataBound(e) {
65+
let grid = this;
66+
let sorts = grid.dataSource.sort(); // Get the currently sorted fields.
67+
68+
var nonSortableIcon = kendo.ui.icon({ icon: 'caret-alt-expand', type: 'svg' }); // Specify the desired SVG icon for the non-sorted columns.
69+
var descSortIcon = kendo.ui.icon({ icon: 'caret-alt-down', type: 'svg' }); // Specify the desired SVG icon for descending order.
70+
var ascSortIcon = kendo.ui.icon({ icon: 'caret-alt-up', type: 'svg' }); // Specify the desired SVG icon for ascending order.
71+
72+
if(sorts == undefined) { // Check if the Grid is sorted initially.
73+
grid.thead.find("th .k-cell-inner .k-link").each(function(){ // Loop through the Grid column headers.
74+
$(this).append(nonSortableIcon); // Add the "nonSortableIcon " icon on all column headers.
75+
});
76+
} else {
77+
// Reset the sort icons.
78+
grid.thead.find("th .k-cell-inner .k-link").each(function(){
79+
if($(this).find("span.k-svg-i-caret-alt-expand").length == 0) {
80+
$(this).find("span.k-icon").remove(); // Remove the "descSortIcon"/"ascSortIcon" icon.
81+
$(this).append(nonSortableIcon); // Add the default icon.
82+
}
83+
});
84+
85+
$.each(sorts, function(i,value) { // Loop through the sorted fields.
86+
let colHeader = grid.thead.find(`th[data-field='${value.field}']`); // Get the column header of the sorted column.
87+
if(colHeader) {
88+
colHeader.find(".k-link span.k-icon").remove(); // Remove the default icon.
89+
if(value.dir == "asc") {
90+
colHeader.find(".k-link").append(ascSortIcon); //Append the custom "ascSortIcon".
91+
}
92+
if(value.dir == "desc") {
93+
colHeader.find(".k-link").append(descSortIcon); //Append the custom "descSortIcon".
94+
}
95+
}
96+
});
97+
}
98+
}
99+
</script>
100+
```
101+
{% if site.core %}
102+
For a runnable example based on the code above, refer to the following REPL samples:
103+
104+
* [Sample code with the Grid HtmlHelper](https://netcorerepl.telerik.com/cyYvlVFq13LOju7R01)
105+
* [Sample code with the Grid TagHelper](https://netcorerepl.telerik.com/QSaPFLPq2056hwO401)
106+
{% else %}
107+
For a runnable example based on the code above, refer to the [REPL example on customizing the default sorting icons of the Grid columns](https://netcorerepl.telerik.com/cyYvlVFq13LOju7R01).
108+
{% endif %}
109+
110+
## More {{ site.framework }} Grid Resources
111+
112+
* [{{ site.framework }} Grid Documentation]({%slug htmlhelpers_grid_aspnetcore_overview%})
113+
114+
* [{{ site.framework }} Grid Demos](https://demos.telerik.com/{{ site.platform }}/grid/index)
115+
116+
{% if site.core %}
117+
* [{{ site.framework }} Grid Product Page](https://www.telerik.com/aspnet-core-ui/grid)
118+
119+
* [Telerik UI for {{ site.framework }} Video Onboarding Course (Free for trial users and license holders)]({%slug virtualclass_uiforcore%})
120+
121+
* [Telerik UI for {{ site.framework }} Forums](https://www.telerik.com/forums/aspnet-core-ui)
122+
123+
{% else %}
124+
* [{{ site.framework }} Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)
125+
126+
* [Telerik UI for {{ site.framework }} Video Onboarding Course (Free for trial users and license holders)]({%slug virtualclass_uiformvc%})
127+
128+
* [Telerik UI for {{ site.framework }} Forums](https://www.telerik.com/forums/aspnet-mvc)
129+
{% endif %}
130+
131+
## See Also
132+
133+
* [Client-Side API Reference of the Grid for {{ site.framework }}](https://docs.telerik.com/kendo-ui/api/javascript/ui/grid)
134+
* [Server-Side API Reference of the Grid for {{ site.framework }}](https://docs.telerik.com/{{ site.platform }}/api/grid)
135+
{% if site.core %}
136+
* [Server-Side TagHelper API Reference of the Grid for {{ site.framework }}](https://docs.telerik.com/{{ site.platform }}/api/taghelpers/grid)
137+
{% endif %}
138+
* [Telerik UI for {{ site.framework }} Breaking Changes]({%slug breakingchanges_2023%})
139+
* [Telerik UI for {{ site.framework }} Knowledge Base](https://docs.telerik.com/{{ site.platform }}/knowledge-base)

src/kendo.core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ function pad(number, digits, end) {
18821882
};
18831883
}
18841884

1885-
function wrap(element, autosize, resize, shouldCorrectWidth = true) {
1885+
function wrap(element, autosize, resize, shouldCorrectWidth = true, autowidth) {
18861886
var percentage,
18871887
outerWidth = kendo._outerWidth,
18881888
outerHeight = kendo._outerHeight,
@@ -1908,7 +1908,7 @@ function pad(number, digits, end) {
19081908
$("<div/>")
19091909
.addClass("k-child-animation-container")
19101910
.css({
1911-
width: width,
1911+
width: autowidth ? "auto" : width,
19121912
height: height
19131913
}));
19141914
parent = element.parent();

src/kendo.data.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3927,7 +3927,7 @@ var __meta__ = {
39273927
options.aggregate = convertDescriptorsField(options.aggregate, that.reader.model);
39283928
}
39293929

3930-
if (!that.options.groupPaging) {
3930+
if (!that.options.groupPaging || !(that.options.serverPaging && that.options.serverGrouping)) {
39313931
delete options.groupPaging;
39323932
}
39333933

@@ -4527,6 +4527,7 @@ var __meta__ = {
45274527
}
45284528

45294529
data.groupPaging = true;
4530+
45304531
clearTimeout(that._timeout);
45314532
that._timeout = setTimeout(function() {
45324533
that._queueRequest(data, function() {

src/kendo.list.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ var __meta__ = {
12351235
animation: list.options.animation,
12361236
isRtl: support.isRtl(list.wrapper),
12371237
autosize: list.options.autoWidth,
1238+
autowidth: list.options.autoWidth,
12381239
activate: () => {
12391240
this._refreshFloatingLabel();
12401241
},

src/kendo.pager.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ var __meta__ = {
288288
} else {
289289
if (width <= 600) {
290290
info.hide();
291-
}
292-
if (options.numeric) {
291+
if (options.numeric) {
292+
that._numericSelect.show();
293+
that.list.hide();
294+
}
295+
} else if (options.numeric) {
293296
that._numericSelect.hide();
294297
}
295298
}

src/kendo.popup.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ var __meta__ = {
166166
viewport: window,
167167
copyAnchorStyles: true,
168168
autosize: false,
169+
autowidth: false,
169170
modal: false,
170171
adjustSize: {
171172
width: 0,
@@ -270,7 +271,7 @@ var __meta__ = {
270271
that._toggleResize(true);
271272
}
272273

273-
that.wrapper = wrapper = kendo.wrap(element, options.autosize, options._resizeOnWrap, shouldCorrectWidth)
274+
that.wrapper = wrapper = kendo.wrap(element, options.autosize, options._resizeOnWrap, shouldCorrectWidth, options.autowidth)
274275
.css({
275276
overflow: HIDDEN,
276277
display: "block",

tests/core/wrap.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ it("container with percent width produces wrapper with percent width", function(
5454
assert.isOk(wrap.children()[0].style.width == "50%");
5555
});
5656

57+
it("k-child-animation-container has auto width when autowidth is set to true", function() {
58+
span.width("100px");
59+
60+
kendo.wrap(span, true, undefined, undefined, true);
61+
assert.isOk(span.parent().attr("style") === "width: auto;");
62+
});
63+
5764
});
5865
}());
5966

tests/data/datasource/group-paging.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,11 @@
342342
assert.equal(updateOuterRangesLengthStub.calls("_updateOuterRangesLength"), 1);
343343
});
344344

345-
it("_params includes a groupPaging parameter if groupPaging is enabled", function() {
345+
it("_params does not include groupPaging parameter if groupPaging is enabled but server operations are false", function() {
346346
var dataSource = remoteDataSource(null, {
347347
total: 100,
348348
serverPaging: false,
349+
serverGrouping: false,
349350
group: {
350351
field: 'ShipAddress'
351352
},
@@ -354,7 +355,7 @@
354355

355356
var params = dataSource._params();
356357

357-
assert.isOk(typeof params.groupPaging != "undefined");
358+
assert.isOk(typeof params.groupPaging == "undefined");
358359
});
359360

360361
it("_params does not include a groupPaging parameter if groupPaging is not enabled", function() {

0 commit comments

Comments
 (0)