2 Answers, 1 is accepted
Check out the following online example that illustrates how you can have a custom editor in the grid widget.
Also, the article below describes using custom editor in more detail:
Regards,
Viktor Tachev
Telerik
Victor,
Can you give me the link to the GitHub repo? I'm trying to solve the same problem, and I'm not having any luck.
Hello Viktor,
I've circle back around to this issue as I have never been able to resolve it. Currently I am attempting to stuff a different dropdown list per row item in the grid. Is this possible? For example, imagine Grid A, has 2 rows.
Imagine Row 1, has student Jim Beam. Jim Beam has order magazine "zz". Magazine "zz" has a default quantity of 12, but Jim would like to order 36, the maximum allowed for magazine "zz".
Now, Row 2, has the same Student, but this time Jim wants to order magazine "qq". Jim has only ordered 1 of these, but he would like to order 49 more, the maximum allow for this magazine.
As you can see, I have a one (student) to many(the types of magazines) to many(the different quantities ) relationship. With this in mind is it possible to create a grid that allows this relationship?
The documentation and the code examples provided work under the assumption that the user will be using the same "categories" over and over again.
Thanks.
In order to implement the behavior you can use an approach similar to the following. Bind the first Grid column to a field called Name for example. The second column will be bound to the field Magazine that can hold the magazine associated to the current record. There can be a Magazines field in the model containing all magazine types. The last field can be Quantity containing the number of ordered magazines.
Essentially the second column would be configured like Category in the example linked below:
As for the quantity - you can use custom validation and implement logic like in the following example.
Regards,
Viktor Tachev
Progress Telerik
This doesn't work. I need to be able to put a List<int> or a List<SelectListItem>. Is this possible? bear in mind that this cannot be done on page load because each of the aforementioned are tied to an id. So the binding happens on the Read().
Thanks.
The DataSource component was designed to work with flat data. Thus, if you would like to bind some of the columns to a collection of items I would recommend using a custom editor and binding it as illustrated in the custom editor demo.
The Category field in the model from the example is decorated with UIHint attribute. This attribute points to the custom editor that would be used for the field.
[UIHint(
"ClientCategory"
)]
public
CategoryViewModel Category
{
get
;
set
;
}
The ClientCategory editor is a partial view located in the /Views/EditorTemplates folder. It looks like below:
@model Kendo.Mvc.Examples.Models.CategoryViewModel
@(Html.Kendo().DropDownListFor(m => m)
.DataValueField(
"CategoryID"
)
.DataTextField(
"CategoryName"
)
.BindTo((System.Collections.IEnumerable)ViewData[
"categories"
])
)
However, you can configure the editor to request the data from a remote service. The dropdown editor configuration would be similar to the one in the following example.
Regards,
Viktor Tachev
Progress Telerik
There is a GitHub repository with examples for various scenarios for the components. If you would like an example for using custom editors you would find the one linked below interesting. Note that it also illustrates how you can define a custom popup editor.
Regards,
Viktor Tachev
Telerik by Progress