Skip to content

Commit 1bdca73

Browse files
author
Kendo Bot
committed
Sync with Kendo UI Professional
1 parent 0aa31aa commit 1bdca73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1964
-254
lines changed

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

Lines changed: 226 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ This article lists some of the most frequently asked questions when working with
1515

1616
By default, the Telerik UI Grid for {{ site.framework }} encodes the HTML entities that are included in its data. To prevent this, call the [`Encoded`](/api/Kendo.Mvc.UI.Fluent/GridBoundColumnBuilder#formatsystemstring) method and pass `false` as its argument.
1717

18+
```HtmlHelper
1819
columns.Bound(o => o.Description).Encoded(false);
20+
```
21+
{% if site.core %}
22+
```TagHelper
23+
<columns>
24+
<column field="Description" encoded="false">
25+
</column>
26+
</columns>
27+
```
28+
{% endif %}
1929

2030
## How can I customize the way properties are displayed in Grid-bound columns?
2131

@@ -59,12 +69,20 @@ Use the `ClientTemplate` method. The value should be a string, which represents
5969
6070
{% endif %}
6171
62-
```HtmlHelper
63-
.Columns(columns =>
64-
{
65-
columns.Bound(p => p.Title).ClientTemplate("<strong>#: Title #</strong>");
66-
})
67-
```
72+
```HtmlHelper
73+
.Columns(columns =>
74+
{
75+
columns.Bound(p => p.Title).ClientTemplate("<strong>#: Title #</strong>");
76+
})
77+
```
78+
{% if site.core %}
79+
```TagHelper
80+
<columns>
81+
<column field="Title" template="<strong>#: Title #</strong>">
82+
</column>
83+
</columns>
84+
```
85+
{% endif %}
6886

6987
## How can I apply conditional logic to client column templates?
7088

@@ -81,6 +99,15 @@ The following example demonstrates the conditions in the `ClientTemplate`.
8199
"# } #"
82100
);
83101
```
102+
{% if site.core %}
103+
```TagHelper
104+
<columns>
105+
<column field="ProductName"
106+
template="# if (HasIcon == true) { # <img [email protected]("~/Content/icons/")#= ProductID #.png alt='#= ProductName # icon'/># } else { ##: ProductName ## } #">
107+
</column>
108+
</columns>
109+
```
110+
{% endif %}
84111

85112
{% if site.mvc %}
86113
## How can I apply conditional logic to column templates for server-bound Grids?
@@ -114,6 +141,15 @@ The following example demonstrates how to display a checkbox in a bound `ColumnC
114141
"/>"
115142
);
116143
```
144+
{% if site.core %}
145+
```TagHelper
146+
<columns>
147+
<column field="Enabled"
148+
template="<input type='checkbox' value='#= ProductID #' # if (Enabled) { # checked='checked'# } #/>">
149+
</column>
150+
</columns>
151+
```
152+
{% endif %}
117153

118154
## How can I use action links?
119155

@@ -137,6 +173,15 @@ The following example demonstrates how to display a checkbox in a bound `ColumnC
137173
">Show Product Details</a>"
138174
);
139175
```
176+
{% if site.core %}
177+
```TagHelper
178+
<columns>
179+
<column field="ProductID"
180+
template="<a href='@Url.Action("ProductDetails", "Product")/#= ProductID #'>Show Product Details</a>">
181+
</column>
182+
</columns>
183+
```
184+
{% endif %}
140185
141186
## How can I use JavaScript functions in client column templates?
142187
@@ -162,6 +207,29 @@ The following example demonstrates how to use a JavaScript function in the `Clie
162207
}
163208
</script>
164209
```
210+
{% if site.core %}
211+
```TagHelper
212+
// Omitted for brevity.
213+
<columns>
214+
<column field="ProductID" template="#= productDetails(data) #">
215+
</column>
216+
</columns>
217+
// Omitted for brevity.
218+
219+
<script>
220+
function productDetails(product) {
221+
var action = '@Url.Action("ProductDetails", "Product")';
222+
223+
var html = kendo.format("<a href='{0}/{1}'>Show Product Details</a>",
224+
action,
225+
product.ProductID
226+
);
227+
228+
return html;
229+
}
230+
</script>
231+
```
232+
{% endif %}
165233

166234
## How can I use Kendo UI widgets inside Grid client column templates?
167235

@@ -229,6 +297,27 @@ The following example demonstrates how to add a Kendo UI Menu inside a Grid colu
229297
.Events(ev => ev.DataBound("initMenus"))
230298
)
231299
```
300+
```TagHelper
301+
<kendo-grid name="GridID" on-data-bound="initMenus">
302+
<columns>
303+
<column field="ProductID"
304+
html-attributes='new Dictionary<string,object> { ["class"] = "templateCell" }'
305+
template="@(Html.Kendo().Menu()
306+
.Name("menu_#=ProductID#")
307+
.Items(its =>
308+
{
309+
its.Add().Text("foo").Items(nested =>
310+
{
311+
nested.Add().Text("bar");
312+
nested.Add().Text("baz");
313+
});
314+
315+
})
316+
.ToClientTemplate().Value)">
317+
</column>
318+
</columns>
319+
</kendo-grid>
320+
```
232321
```JavaScript
233322
function initMenus(e) {
234323
$(".templateCell").each(function(){
@@ -250,7 +339,18 @@ Use the [`Format`](/api/Kendo.Mvc.UI.Fluent/GridBoundColumnBuilder#formatsystems
250339

251340
The following example demonstrates how to specify the format of a bound column.
252341

342+
```HtmlHelper
253343
columns.Bound(o => o.OrderDate).Format("{0:d}"); // Will use the short date pattern
344+
```
345+
{% if site.core %}
346+
```TagHelper
347+
<columns>
348+
<column field="OrderDate" format="{0:d}">
349+
</column>
350+
</columns>
351+
```
352+
{% endif %}
353+
254354

255355
## How can I add Kendo UI icons to custom command buttons?
256356

@@ -267,6 +367,19 @@ The following example demonstrates how to add Kendo UI icons to custom command b
267367
})
268368
)
269369
```
370+
{% if site.core %}
371+
```TagHelper
372+
<kendo-grid name="grid">
373+
<columns>
374+
<column>
375+
<commands>
376+
<column-command name="myCommand" text="My Text" icon-class="k-icon k-i-custom" />
377+
</commands>
378+
</column>
379+
</columns>
380+
</kendo-grid>
381+
```
382+
{% endif %}
270383

271384
## How can I send values to my action method when binding the Grid?
272385

@@ -306,6 +419,25 @@ The following example demonstrates how to send additional data in an Ajax-bound
306419
}
307420
</script>
308421
```
422+
{% if site.core %}
423+
```TagHelper
424+
// Omitted for brevity.
425+
<datasource type="DataSourceTagHelperType.Ajax">
426+
<transport>
427+
<read url="@Url.Action("Read","Home")" data="additionalData"/>
428+
</transport>
429+
</datasource>
430+
// Omitted for brevity.
431+
<script>
432+
function additionalData() {
433+
return {
434+
userID: 42,
435+
search: $("#search").val()
436+
};
437+
}
438+
</script>
439+
```
440+
{% endif %}
309441

310442
> The property names of the object that are passed as additional data must not match the property names in the `ViewModel`. Otherwise, the MVC binder will not recognize which property corresponds to the `ViewModel` and which to the additional `data` object.
311443
@@ -391,6 +523,20 @@ The following example demonstrates how to handle errors in the Ajax binding mode
391523
}
392524
</script>
393525
```
526+
{% if site.core %}
527+
```TagHelper
528+
// Omitted for brevity.
529+
<datasource type="DataSourceTagHelperType.Ajax" on-error="onError">
530+
</datasource>
531+
// Omitted for brevity.
532+
<script>
533+
function onError(e, status) {
534+
alert("A server error has occurred!");
535+
}
536+
</script>
537+
```
538+
{% endif %}
539+
394540

395541
## How can I see what the server response is?
396542

@@ -424,6 +570,14 @@ The following example demonstrates how to perform paging, sorting, filtering, an
424570
.ServerOperation(false)
425571
// Omitted for brevity.
426572
```
573+
{% if site.core %}
574+
```TagHelper
575+
// Omitted for brevity.
576+
<datasource type="DataSourceTagHelperType.Ajax" server-operation="false">
577+
</datasource>
578+
// Omitted for brevity.
579+
```
580+
{% endif %}
427581

428582
## How can I prevent Ajax response caching?
429583

@@ -482,6 +636,29 @@ The following example demonstrates how to display model state errors.
482636
}
483637
</script>
484638
```
639+
{% if site.core %}
640+
```TagHelper
641+
// Omitted for brevity.
642+
<datasource type="DataSourceTagHelperType.Ajax" on-error="onError">
643+
</datasource>
644+
// Omitted for brevity.
645+
<script>
646+
function onError(e, status) {
647+
if (e.errors) {
648+
var message = "The following errors have occurred:\n";
649+
650+
$.each(e.errors, function(key, value) {
651+
if (value.errors) {
652+
message += value.errors.join("\n");
653+
}
654+
});
655+
656+
alert(message);
657+
}
658+
}
659+
</script>
660+
```
661+
{% endif %}
485662
## How can I create custom pop-up editors?
486663

487664
The Kendo UI Grid for {{ site.framework }} uses the `Html.EditorForModel` to create the editing form. This method relies on {{ site.framework }} editor templates. To create a custom editor template, create a partial view under the `~/Views/Shared/EditorTemplates` folder and specify it through the `UIHint` attribute.
@@ -510,6 +687,22 @@ The following example demonstrates how to specify default property values.
510687
})
511688
// Omitted for brevity.
512689
```
690+
{% if site.core %}
691+
```TagHelper
692+
// Omitted for brevity.
693+
<datasource type="DataSourceTagHelperType.Ajax">
694+
<schema>
695+
<model>
696+
<fields>
697+
<field name="Name" type="string" default-value="N/A"></field>
698+
<field name="Price" type="number" default-value=9.99></field>
699+
</fields>
700+
</model>
701+
</schema>
702+
</datasource>
703+
// Omitted for brevity.
704+
```
705+
{% endif %}
513706

514707
## How can I create helper methods rendering predefined widgets I can further configure?
515708

@@ -562,6 +755,21 @@ The following example demonstrates the Read-only property through the `Editable`
562755
})
563756
// Omitted for brevity.
564757
```
758+
{% if site.core %}
759+
```TagHelper
760+
// Omitted for brevity.
761+
<datasource type="DataSourceTagHelperType.Ajax">
762+
<schema>
763+
<model>
764+
<fields>
765+
<field name="OrderID" type="number" editable="false"></field>
766+
</fields>
767+
</model>
768+
</schema>
769+
</datasource>
770+
// Omitted for brevity.
771+
```
772+
{% endif %}
565773

566774
> The `ReadOnly` and `Editable` settings work only in in-line and in-cell editing modes. Use a custom popup editor if you want to exclude certain properties from the editor form.
567775
@@ -580,6 +788,12 @@ To validate a date by using the Kendo UI DateTimePicker:
580788
.DateInput()
581789
)
582790
```
791+
{% if site.core %}
792+
```TagHelper
793+
<kendo-datetimepicker value="DateTime.Now" date-input="true">
794+
</kendo-datetimepicker>
795+
```
796+
{% endif %}
583797
584798
1. Decorate the `Date` property in the model by using the [`UIHint`](https://msdn.microsoft.com/en-us/library/cc679268) attribute.
585799
@@ -604,6 +818,12 @@ To validate a number by using the Kendo UI NumericTextBox:
604818
.Spinners(false)
605819
)
606820
```
821+
{% if site.core %}
822+
```TagHelper
823+
<kendo-numerictextbox round="true" spinners="false">
824+
</kendo-numerictextbox>
825+
```
826+
{% endif %}
607827
608828
1. Decorate the `number` property in the model by using the [`UIHint`](https://msdn.microsoft.com/en-us/library/cc679268) attribute.
609829

0 commit comments

Comments
 (0)