Skip to content

Commit 3e0f780

Browse files
author
Kendo Bot
committed
Sync with Kendo UI Professional
1 parent b10a36a commit 3e0f780

File tree

4 files changed

+229
-6
lines changed

4 files changed

+229
-6
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
title: Use DropDownList as Boolean Filter in Grid
3+
description: How can I set up a custom filter for a Boolean column in the Grid and have a DropDownList which lists true, false, all?
4+
type: how-to
5+
page_title: Filter Boolean Grid Column with DropDownList
6+
slug: grid-boolean-dropdownlist-filter
7+
tags: grid, dropdownlist, filter, boolean, column, true, false
8+
res_type: kb
9+
---
10+
11+
## Environment
12+
13+
<table>
14+
<tbody>
15+
<tr>
16+
<td>Product</td>
17+
<td>Progress® Telerik® UI Grid for {{ site.product_short }}</td>
18+
</tr>
19+
</tbody>
20+
</table>
21+
22+
## Description
23+
24+
How can I set up a custom filter for a Boolean column in the Grid and have a DropDownList which lists true, false, all?
25+
26+
## Solution
27+
28+
1. Create a template function to initialize the DropDownList.
29+
```
30+
function boolFilterTemplate(input) {
31+
input.kendoDropDownList({
32+
dataSource: {
33+
data: [
34+
{ text: "True", value: true },
35+
{ text: "False", value: false }
36+
]
37+
},
38+
dataTextField: "text",
39+
dataValueField: "value",
40+
valuePrimitive: true,
41+
optionLabel: "All"
42+
});
43+
}
44+
```
45+
46+
2. Use the [filterMenuInit](https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/events/filtermenuinit) event of the Grid to replace the default filter label with more appropriate text.
47+
48+
```
49+
function onFilterMenuInit(e) {
50+
if (e.field == "Discontinued") {
51+
// replace default text in filter menu
52+
e.container.find(".k-filter-help-text").text("Show items with value:");
53+
}
54+
}
55+
```
56+
57+
3. Use the [filter](https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/events/filter) event of the Grid to replace the string value in the generated filter expression with its Boolean equivalent.
58+
59+
```
60+
function onFilter(e) {
61+
if (e.field === "Discontinued") {
62+
var filter = e.filter;
63+
if (filter && filter.filters && filter.filters.length > 0) {
64+
var filters = filter.filters;
65+
// convert the filter string value to a boolean one
66+
filters[0].value = (filters[0].value === "true");
67+
}
68+
}
69+
}
70+
```
71+
Example:
72+
73+
```View
74+
@(Html.Kendo().Grid<BooleanFilterGrid.Models.OrderViewModel>()
75+
.Name("grid")
76+
.Columns(columns =>
77+
{
78+
columns.Bound(p => p.OrderID).Filterable(false);
79+
columns.Bound(p => p.Freight);
80+
columns.Bound(p => p.IsTrue);
81+
82+
})
83+
.Pageable()
84+
.Scrollable()
85+
.Filterable()
86+
.Events(ev=>ev.Filter("onFilter"))
87+
.HtmlAttributes(new { style = "height:440px;" })
88+
.DataSource(dataSource => dataSource
89+
.Ajax()
90+
.PageSize(10)
91+
.Read(read => read.Action("Orders_Read", "Grid"))
92+
)
93+
)
94+
```
95+
```script.js
96+
$(document).ready(function () {
97+
var grid = $("#grid").data('kendoGrid');
98+
var options = grid.getOptions();
99+
options.columns[2].filterable = { ui: boolFilterTemplate };
100+
options.filterMenuOpen = onFilterMenuInit;
101+
grid.setOptions(options);
102+
103+
function boolFilterTemplate(input) {
104+
input.kendoDropDownList({
105+
dataSource: {
106+
data: [
107+
{ text: "True", value: true },
108+
{ text: "False", value: false }
109+
]
110+
},
111+
dataTextField: "text",
112+
dataValueField: "value",
113+
valuePrimitive: true,
114+
optionLabel: "All"
115+
});
116+
}
117+
118+
function onFilterMenuInit(e) {
119+
if (e.field == "IsTrue") {
120+
// replace default text in filter menu
121+
e.container.find(".k-filter-help-text").text("Show items with value:");
122+
}
123+
}
124+
});
125+
126+
function onFilter(e) {
127+
if (e.field === "IsTrue") {
128+
var filter = e.filter;
129+
if (filter && filter.filters && filter.filters.length > 0) {
130+
var filters = filter.filters;
131+
// convert the filter string value to a boolean one
132+
filters[0].value = (filters[0].value === "true");
133+
}
134+
}
135+
}
136+
```
137+
```Controller
138+
public partial class GridController : Controller
139+
{
140+
public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
141+
{
142+
var result = Enumerable.Range(0, 50).Select(i => new OrderViewModel
143+
{
144+
OrderID = i,
145+
Freight = i * 10,
146+
OrderDate = DateTime.Now.AddDays(i),
147+
ShipName = "ShipName " + i,
148+
ShipCity = "ShipCity " + i,
149+
IsTrue = i % 2 == 0
150+
}) ;
151+
152+
return Json(result.ToDataSourceResult(request));
153+
}
154+
}
155+
```
156+
```Model
157+
public class OrderViewModel
158+
{
159+
public int OrderID { get; set; }
160+
public bool IsTrue { get; set; }
161+
public decimal? Freight { get; set; }
162+
[Required]
163+
public DateTime? OrderDate { get; set; }
164+
public string ShipCity { get; set; }
165+
166+
public string ShipName{ get; set; }
167+
168+
}
169+
```

docs-aspnet/knowledge-base/grid-export-custom-file-name.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ res_type: kb
1212

1313
<table>
1414
<tbody>
15-
<tr>
15+
<tr>
1616
<td>Product</td>
17-
<td>Progress® Kendo UI® Grid for ASP.NET MVC</td>
17+
<td>Grid for Progress® Telerik® {{ site.product_short }}</td>
1818
</tr>
1919
</tbody>
2020
</table>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Transfer ListBox Items on Double Click
3+
description: How can I transfer items between ListBoxes by double-clicking the Kendo UI ListBox?
4+
type: how-to
5+
page_title: ListBox Move elements on double click
6+
slug: listbox-move-double-click
7+
tags: listbox, list, box, double, click, transfer, items
8+
res_type: kb
9+
---
10+
11+
## Environment
12+
13+
<table>
14+
<tbody>
15+
<tr>
16+
<td>Product</td>
17+
<td>Progress® Telerik® UI ListBox for {{ site.product_short }}</td>
18+
</tr>
19+
</tbody>
20+
</table>
21+
22+
## Description
23+
24+
How can I transfer items between ListBoxes by double-clicking the Kendo UI ListBox?
25+
26+
## Solution
27+
28+
1. Handle the [dblclick](https://api.jquery.com/dblclick/) event on the items in both ListBoxes.
29+
2. In the event handler, based on the ListBox, manually execute the `transferTo` or `transferFrom` command.
30+
31+
```Index.cshtml
32+
@(Html.Kendo().ListBox()
33+
.Name("listBoxA")
34+
.ConnectWith("listBoxB")
35+
.BindTo(new List<string>() { "Value 1", "Value 2", "Value 3"}))
36+
37+
@(Html.Kendo().ListBox()
38+
.Name("listBoxB")
39+
.BindTo(new List<string>())
40+
.Selectable(ListBoxSelectable.Multiple))
41+
```
42+
```script.js
43+
$(document).ready(function () {
44+
var listBoxB = $("#listBoxB").data("kendoListBox");
45+
var listBoxA = $("#listBoxA").data("kendoListBox");
46+
listBoxA.wrapper.find(".k-list").on("dblclick", ".k-item", function (e) {
47+
listBoxA._executeCommand("transferTo");
48+
});
49+
50+
listBoxB.wrapper.find(".k-list").on("dblclick", ".k-item", function (e) {
51+
listBoxA._executeCommand("transferFrom");
52+
});
53+
})
54+
```

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": "4.43.0",
15-
"@progress/kendo-theme-default": "4.43.0",
16-
"@progress/kendo-theme-material": "4.43.0",
17-
"@progress/kendo-theme-classic": "4.43.0",
14+
"@progress/kendo-theme-bootstrap": "4.42.0",
15+
"@progress/kendo-theme-default": "4.42.0",
16+
"@progress/kendo-theme-material": "4.42.0",
17+
"@progress/kendo-theme-classic": "4.42.0",
1818
"amd-optimize": "0.6.1",
1919
"autoprefixer": "^9.1.5",
2020
"axe-core": "^4.3.0",

0 commit comments

Comments
 (0)