Skip to content

Commit f75c03c

Browse files
author
Kendo Bot
committed
Sync with Kendo UI Professional
1 parent aa49429 commit f75c03c

File tree

8 files changed

+318
-24
lines changed

8 files changed

+318
-24
lines changed

docs-aspnet/html-helpers/data-management/grid/selection.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ You can set the select mode to `Multiple` or `Single`. Additionally, the Grid pr
101101
```
102102
{% endif %}
103103

104+
## Drag to Select
105+
106+
The Grid allows conditional drag to select when multiple selection is configured for rows or cells through the `DragToSelect` property.
107+
108+
```HtmlHelper
109+
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
110+
.Name("cellSelection")
111+
.Selectable(selectable => selectable
112+
.DragToSelect(false)
113+
.Mode(GridSelectionMode.Multiple)
114+
.Type(GridSelectionType.Row))
115+
...
116+
```
117+
{% if site.core %}
118+
```TagHelper
119+
<kendo-grid name="cellSelection">
120+
<selectable dragToSelect="false" mode="multiple, row"/>
121+
</kendo-grid>
122+
```
123+
{% endif %}
104124

105125
## Persisting the Selection
106126

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
---
2+
title: Enable ForeignKey Column Sorting by Text
3+
page_title: ForeignKey Column Sorting by Text
4+
description: "An example on how to enable ForeignKey column sorting by text in the Telerik UI Grid for {{ site.framework }}."
5+
slug: howto_enable_foreignkey_sotringby_text_grid
6+
tags: grid, enable, foreignkey, column, sort, text
7+
component: grid
8+
type: how-to
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tr>
16+
<td>Product</td>
17+
<td>Telerik {{ site.product_short }} Grid</td>
18+
</tr>
19+
<tr>
20+
<td>Operating System</td>
21+
<td>Windows 10 64bit</td>
22+
</tr>
23+
</table>
24+
25+
## Description
26+
27+
How can I enable ForeignKey column sorting by text in the {{ site.product }} Grid?
28+
29+
## Solution
30+
31+
The following example demonstrates how to enable the sort-by-text functionality in a ForeignKey column by using a calculated field in a Grid.
32+
33+
* Create an additional text field that will be used for sorting in the ViewModel of the Grid.
34+
```
35+
public class ProductViewModel
36+
{
37+
public string CategoryName
38+
{
39+
get;
40+
set;
41+
}
42+
}
43+
```
44+
45+
* Prepopulate the data for the Foreign Key column within the controller.
46+
```
47+
public class GridController : Controller
48+
{
49+
public IActionResult Index()
50+
{
51+
ViewData["categories"] = GetCategories();
52+
return View();
53+
}
54+
}
55+
```
56+
57+
* Create a dictionary of key-value pairs using the prepopulated data.
58+
```
59+
<script type="text/javascript">
60+
var categories= @Html.Raw(Json.Serialize(@ViewData["categories"])); //serialize the data
61+
62+
//create dictionary of text-values for the FKC
63+
var categoriesDict = {};
64+
for (var i = 0; i < categories.length; i++) {
65+
categoriesDict[categories[i].CategoryID] = categories[i].CategoryName;
66+
}
67+
</script>
68+
69+
```
70+
* Bind the additional text field using the [.Bound()](https://docs.telerik.com/aspnet-core/api/Kendo.Mvc.UI.Fluent/GridColumnFactory?&_ga=2.8632309.1913833702.1649765178-415541100.1638373975#boundsystemlinqexpressionsexpressionsystemfunctt1) configuration option and calculate the field by utilizing the [.ClientTemplate()](https://docs.telerik.com/aspnet-core/api/Kendo.Mvc.UI.Fluent/GridBoundColumnBuilder#clienttemplatesystemstring) setting.
71+
```
72+
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
73+
.Name("grid")
74+
.Columns(columns =>
75+
{
76+
columns.Bound(p => p.CategoryName).ClientTemplate("#=calculateField(CategoryID)#").EditorTemplateName("CategoryNameEditor");
77+
78+
})
79+
)
80+
81+
82+
<script type="text/javascript">
83+
function calculateField(categoryId){
84+
return categoriesDict[categoryId];
85+
}
86+
</script>
87+
```
88+
* Specify a DropDownList for the text field editor in the **~View/Shared/EditorTemplates** folder and specify the value field with the **data-bind** attribute.
89+
```
90+
@model ProductViewModel
91+
92+
@(Html.Kendo().DropDownListFor(m => m.CategoryName)
93+
.DataValueField("CategoryID")
94+
.DataTextField("CategoryName")
95+
.AutoBind(false)
96+
.HtmlAttributes(new {data_bind="value:CategoryID"})
97+
.BindTo((System.Collections.IEnumerable)ViewData["categories"])
98+
)
99+
100+
```
101+
102+
Example:
103+
104+
```Model
105+
public class ProductViewModel
106+
{
107+
public int ProductID
108+
{
109+
get;
110+
set;
111+
}
112+
113+
public string ProductName
114+
{
115+
get;
116+
set;
117+
}
118+
119+
public decimal UnitPrice
120+
{
121+
get;
122+
set;
123+
}
124+
125+
126+
[UIHint("CategoryNameEditor")]
127+
public string CategoryName
128+
{
129+
get;
130+
set;
131+
}
132+
133+
public int? CategoryID { get; set; }
134+
}
135+
```
136+
```Index.cshtml
137+
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
138+
.Name("grid")
139+
.Columns(columns =>
140+
{
141+
columns.Bound(p => p.ProductName);
142+
columns.Bound(p => p.CategoryName).ClientTemplate("#=calculateField(CategoryID)#").EditorTemplateName("CategoryNameEditor").Width(200);
143+
columns.Bound(p => p.UnitPrice).Format("{0:c}").Width(200);
144+
columns.Command(command => command.Destroy()).Width(150);
145+
})
146+
.ToolBar(toolBar =>
147+
{
148+
toolBar.Create();
149+
toolBar.Save();
150+
})
151+
.Editable(editable => editable.Mode(GridEditMode.InCell))
152+
.Pageable()
153+
.Sortable()
154+
.Scrollable()
155+
.HtmlAttributes(new { style = "height:540px;" })
156+
.DataSource(dataSource => dataSource
157+
.Ajax()
158+
.Batch(true)
159+
.PageSize(20)
160+
.ServerOperation(false)
161+
.Model(model =>
162+
{
163+
model.Id(p => p.ProductID);
164+
model.Field(p => p.ProductID).Editable(false);
165+
})
166+
.Read(read => read.Action("Products_Read", "Grid"))
167+
.Update(update => update.Action("Products_Update", "Grid"))
168+
.Create(create => create.Action("Products_Create", "Grid"))
169+
.Destroy(destroy => destroy.Action("Products_Destroy", "Grid"))
170+
)
171+
)
172+
```
173+
```Controller
174+
public class GridController : Controller
175+
{
176+
public IActionResult Index()
177+
{
178+
ViewData["categories"] = GetCategories();
179+
return View();
180+
}
181+
public IEnumerable<CategoryViewModel> GetCategories()
182+
{
183+
var firms = Enumerable.Range(1, 10)
184+
.Select(i => new CategoryViewModel
185+
{
186+
CategoryID = i,
187+
CategoryName = "CategoryName " + i
188+
}).ToList();
189+
190+
return firms;
191+
}
192+
public IActionResult Products_Read([DataSourceRequest] DataSourceRequest request)
193+
{
194+
IEnumerable<ProductViewModel> products = GetProducts();
195+
196+
return Json(products.ToDataSourceResult(request));
197+
}
198+
199+
private static IEnumerable<ProductViewModel> GetProducts()
200+
{
201+
return Enumerable.Range(1, 20)
202+
.Select(i => new ProductViewModel
203+
{
204+
ProductID = i,
205+
ProductName = "ProductName" + i,
206+
UnitPrice = 1250.50M,
207+
CategoryID = i % 5
208+
});
209+
}
210+
}
211+
```
212+
```CategoryNameEditor.cshtml
213+
@model ProductViewModel
214+
215+
@(Html.Kendo().DropDownListFor(m=>m.CategoryName)
216+
.DataValueField("CategoryID")
217+
.DataTextField("CategoryName")
218+
.AutoBind(false)
219+
.HtmlAttributes(new {data_bind="value:CategoryID"})
220+
.BindTo((System.Collections.IEnumerable)ViewData["categories"])
221+
)
222+
223+
```
224+
```JavaScript
225+
<script type="text/javascript">
226+
var categories= @Html.Raw(Json.Serialize(@ViewData["categories"]));
227+
228+
//create dictionary of text-values for the FKC
229+
var categoriesDict = {};
230+
for (var i = 0; i < categories.length; i++) {
231+
console.log(categories[i]);
232+
categoriesDict[categories[i].CategoryID] = categories[i].CategoryName;
233+
}
234+
235+
function calculateField(firmId){
236+
return categoriesDict[firmId];
237+
}
238+
</script>
239+
```

docs/api/javascript/ui/editor.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,6 +2262,24 @@ Indicates whether the characters outside the ASCII range will be encoded as HTML
22622262
console.log($("#editor").data("kendoEditor").value()); // logs "The character &auml; is an umlaut"
22632263
</script>
22642264

2265+
### serialization.optimizeTags `Boolean` *(default: false)*
2266+
2267+
Indicates whether optizable tags should be removed from the DOM. Currently, optimizable tags are `span` and `font` elements with no attributes and no decoration or formatting applied (via inline styles/attributes).
2268+
2269+
#### Example
2270+
2271+
<textarea id="editor"></textarea>
2272+
<script>
2273+
$("#editor").kendoEditor({
2274+
value: "<p><span>non-decorated text</span></p><p><span style=\"text-decoration: underline;\">underline text</span></p>",
2275+
serialization: {
2276+
optimizeTags: true
2277+
}
2278+
});
2279+
/* The result can be observed in the DevTools(F12) console of the browser. */
2280+
console.log($("#editor").data("kendoEditor").value()); // logs "The character &auml; is an umlaut"
2281+
</script>
2282+
22652283
### serialization.scripts `Boolean` *(default: false)*
22662284

22672285
Indicates whether inline scripts will be serialized and posted to the server.

docs/intro/installation/using-license-code.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The license key installation process involves two steps:
2323

2424
## Getting a License Key
2525

26+
<link rel="stylesheet" href="https://d3fu8oi3wk1rz4.cloudfront.net/kendo-docs-demos-assets/0.0.1/styles/license-key/styles.css" />
2627
<script src="https://d3fu8oi3wk1rz4.cloudfront.net/kendo-docs-demos-assets/0.0.1/scripts/license-key/index.js"></script>
2728

2829
<license-download-link

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"version": "1.0.0",
1212
"dependencies": {},
1313
"devDependencies": {
14-
"@progress/kendo-theme-bootstrap": "5.3.0",
15-
"@progress/kendo-theme-classic": "5.3.0",
16-
"@progress/kendo-theme-default": "5.3.0",
17-
"@progress/kendo-theme-material": "5.3.0",
14+
"@progress/kendo-theme-bootstrap": "5.4.0",
15+
"@progress/kendo-theme-classic": "5.4.0",
16+
"@progress/kendo-theme-default": "5.4.0",
17+
"@progress/kendo-theme-material": "5.4.0",
1818
"autoprefixer": "^9.1.5",
1919
"axe-core": "^4.3.0",
2020
"bootstrap": "^4.0.0",

0 commit comments

Comments
 (0)