Telerik Forums
UI for ASP.NET MVC Forum
11 answers
2.1K+ views
I would like to create a custom Html helper for a Kendo grid. We have a particular view-model combination which will be used across multiple controllers. I would like to be able to create a custom help method for display a grid of these models. It would basically be a short cut to use in all the views so we wouldn't have to maintain the same code in many different files. I would like to call it like this:

@Html.Kendo().ConfigruationGrid();
@* or *@
@Html.ConfigurationKendoGrid();
And have it output all the bells and whistles of a full grid declaration, like this:
@(Html.Kendo().Grid(@Model)
    .Name("KnockoutQuestions")
    .DataSource(datasource => datasource
        .Ajax()
        .Model(model =>
            {
                model.Id(k => k.Id);
                model.Field(k => k.Id).Editable(false);
                model.Field(k => k.Enabled).DefaultValue(true);
            })
        .Events(events => events.Error("Error"))
        .Create(create => create.Action("Create", "KnockOutQuestion"))
        .Read(read => read.Action("Read", "KnockOutQuestion"))
        .Update(update => update.Action("Update", "KnockOutQuestion"))
    )
    .Columns(columns => {
        columns.ForeignKey(k => k.AdminLeadType,
            new SelectList(from pair in BaseKnockOutQuestionModel.EnumLeadTypes select new { text = pair.Value, value = pair.Key },
                   "value", "text"));
        columns.ForeignKey(k => k.QuestionTypeId,
            new SelectList(from pair in BaseKnockOutQuestionModel.QuestionTypes select new { text = pair.Value, value = pair.Key },
                   "value", "text"));
        columns.Bound(k => k.QuestionText);
        columns.Bound(k => k.Answer1Text);
        columns.Bound(k => k.Answer2Text);
        columns.Bound(k => k.Price);
        columns.Bound(k => k.Enabled);
        columns.Command(command => command.Edit());
    })
    .ToolBar(toolbar => { toolbar.Create(); })
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .Pageable()
    .Sortable()
    .Filterable()
    )
I know how to do custom Html helper methods, but I haven't found any examples of how to do a shortcut like this. It's probably something simple like using the "this HtmlHelper helper" param to execute and return the output of the Kendo().Grid() function. I wanted to ask anyways so I could hopefully avoid common mistakes/pitfalls.
Dimo
Telerik team
 answered on 10 Aug 2016
2 answers
138 views

Hi,

A error was encounted when I installed Telerik.UI.for.Aspnet.Core (v2016.2.714) by NuGet in VS2015. The error detail is as the attached file.

Could you please help to check them and tell me how to install it correctly. Is there any special setting in VS2015 for the installation?

BTW, I can't submit support ticket through login of my account now (investigating cause), I want to get your help from here as suggest from your support team.

 

Regards,

Amstrong

Aug.8, 2016

Amstrong
Top achievements
Rank 1
 answered on 10 Aug 2016
1 answer
344 views

Hello,

I have a grid with a  Editor Template with one TextBox and a Upload Control (see Code)

in the Upload Control Client Event "Success" I want to set the filename to the TextBox Control - how to Access the TextBox Control in edit mode of the template from this Event?

@model string
@using Kendo.Mvc.UI
 
@Html.TextBoxFor(model => model, new { @class = "k-textbox" })
@(Html.Kendo()
            .Upload()
            .Multiple(false)
            .Messages(m => m.HeaderStatusUploaded("Erfolgreich"))
            .Messages(m => m.Select("Word Dokument hochladen..."))
            //.HtmlAttributes(new { accept = "application/pdf" })
            .Name("Wordvorlage1Upload")
            .Async(a => a
            .Save("Save", "Auszeichnungsart")
            .AutoUpload(true)
          )
         .Events(events => events
              .Upload("onUpload")
              .Success("onUploadSuccess")
          )
)

the Javascript Events

function onUpload(e) {
        //var grid = $("#grid").data("kendoGrid");
        //grid.saveChanges();
        e.data = { Auszeichnungsart_ID: $("#Auszeichnungsart_ID").val() };
    }
 
    function onUploadSuccess(e) {
        alert(e.files[0].name);

    here I want to set the TextBox value of the edit template

        var grid = $("#grid").data("kendoGrid");
        grid.dataSource.read();
    }

Eyup
Telerik team
 answered on 09 Aug 2016
1 answer
2.8K+ views

Greetings!

 

I've implemented an EditorTemplate that uses Kedno.DropDownList for one of the model properties. Here is an example of it

1.@(Html.Kendo().DropDownList()
2.          .Name(ViewData.ModelMetadata.AdditionalValues["id"].ToString())
3.          .OptionLabel("not selected")
4.          .DataTextField("Name")
5.          .DataValueField("Id")
6.          .DataSource(ds => ds.Read(a => a.Action("GetAvailiableOrders","Orders")))
7.          .Filter(FilterType.Contains)
8.

I use this model to populate grid, like so

01.@(
02.    Html.Kendo().Grid<CustomerViewModel>()
03.    .Name("customersGrid")   
04.    .ToolBar(toolbar =>
05.    {
06.        if (!Model.ReadOnly)
07.        {
08.            toolbar.Create();
09.        }
10.    })
11.    .Editable(e => e.Mode(GridEditMode.InLine).CreateAt(GridInsertRowPosition.Bottom))
12.    .Resizable(resize => resize.Columns(true))
13.    .Columns(c => {
14.        c.Bound(s => s.Order); //EditorTemplate will be used here
15.        c.Bound(s => s.ConsumerName).Format("{0:dd.MM.yyyy}");
16.        c.Bound(s => s.OrderDate).Format("{0:dd.MM.yyyy}");
17.        if (!Model.ReadOnly)
18.        {
19.            c.Command(command =>
20.            {
21.                command.Edit();
22.                command.Destroy();
23.            });
24.        }
25.    })
26.    .DataSource(d => d.Ajax().
27.    Model(m =>
28.    {
29.        m.Id(p => p.Id);
30.        m.Field(p => p.Id).DefaultValue(default(long));
31.    })
32.    .Read(a => a.Action("GetCostumers","Costumers"))
33.    .Create(a => a.Action("CreateCostumer", "Costumers"))
34.    .Update(a => a.Action("UpdateCostumer","Costumers"))
35.    .Destroy(a => a.Action("DeleteCostumer", "Costumers"))
36.    )
37.)

I need some how to pass additional argument to the DataSource Read method,this parameter depends on other model property an is uiniqe for each grid row.

.DataSource(ds => ds.Read(a => a.Action("GetAvailiableOrders","Orders"))) //Need to pass additional argument here dependting on current row

Is there any way to implement this?

Ivan Danchev
Telerik team
 answered on 09 Aug 2016
1 answer
83 views

Hi,

I have a grid with some of the filters set. In the toolbar I have a new button going to a new page.

After inserting a new line in the grid I want to go back to the origional grid and set all the filters again.

 

Is this possible?

 

In the example in the attachment:

I have filtered on Project Number and Project Subnumber and pressed new which give me the bottom part of the image on a new webpage.

 

After pressing back or save I want to let the user going back to the old filtered information.

 

With kind regards,

 

Maurice Lucas

 

Konstantin Dikov
Telerik team
 answered on 09 Aug 2016
2 answers
268 views

I have two grids with pageSize enabled which includes 'All' text to display all the items of the grid. There is a button in the form which when clicked will move items from one grid to other. The issue is when i select pageSize 'All' and click the button to move the item, the pageSize label changes to total count of the grid item. e.g. if grid1 has 50 items and if i move 1 item from grid1 to grid2, the pageSize text 'All' changes to '50' in grid1 after the move is performed. 

I have created sample which has grid and delete button to remove one item from grid to mock this behavior. To replicate this behavior, select 'All' in the grid and click 'Delete' button. You should see '4' in the pageSize after the removal of the item from the grid. 

http://dojo.telerik.com/eqIDe/2

Is there anyway to have 'All' text selected even after the removal of item from grid1?

Thanks.

Avinash

Avinash
Top achievements
Rank 1
 answered on 08 Aug 2016
4 answers
1.9K+ views

I'm struggling on how to set the color of a cell in the grid based on data.  I see where this question has been asked a lot before - but I'm not seeing an answer that is understandable to me.

I am using ASP.NET MVC with a grid that has an AJAX datasource.  The datasource returns a column that contains the color I want the cell to be. 

The view's model contains the selection fields for the page.  The grid is using a different class named: PlannedProjectList.  There is a field in PlannedProjectList that contains the color of the cell.

@model LRFP.ViewModels.PlannedProjectSelection 

@(Html.Kendo().Grid<LRFP.ViewModels.PlannedProjectList>()

 

I was able to set the color of the cell with this.  But I don't want to use a model field.  Because each row can be a different color.  So I need to use a field from the data on the grid.

columns.Bound(c => c.PlannedProjectName).HtmlAttributes(new { style = "color: " +  @Model.fieldColor + "  ;" });

Is it possible to do what I'm asking?  Or is there another way?  If so, please show a detailed example.  I'm a newbie - so the more detailed example the better.

Thanks for your help.

Terry
Top achievements
Rank 1
 answered on 08 Aug 2016
2 answers
69 views

I'm trying to get around a bug with the Kendo Editor control in Internet Explorer (tested in IE11).

JS Fiddle here:
https://jsfiddle.net/L5tvccd9/

 

Repro steps:
1. Click inside one word (e.g. "nine")
2. Select All (Ctrl+A, but it also happens with example select all from docs: http://docs.telerik.com/kendo-ui/api/javascript/ui/editor#methods-selectRange )
3. Click inside a different word (e.g. "five")
4. Press return on the keyboard

 

Expected behaviour is to insert a break inside the second selected word, where the caret correctly appears (e.g. "five")

Actual behaviour is to insert a break inside the first selected word, where the caret was before select all (e.g. "nine")

This also breaks a lot of other features, like setting the style buttons to the correct state because it doesn't know where the caret is.

A second click in the same location, or using the keyboard cursor keys etc. correctly sets the caret position.

Also reproducible on the demo control:
http://demos.telerik.com/kendo-ui/editor/index

 

Is there any fix or workaround for this?

Ianko
Telerik team
 answered on 08 Aug 2016
0 answers
101 views

Hi, 

I installed  telerik.ui.for.aspnet.core(v2016.2.714) by NuGet in VS2015, but I got a error like the attached NuGet installation image and log. Could you please help to check it? Is there any special setting for the installation?

BTW, I can't submit my support ticket through login to my account (investigating), I want to get your support from here as suggest from your support team.

Regards,

Amstrong,

Aug.8, 2016

Amstrong
Top achievements
Rank 1
 asked on 08 Aug 2016
5 answers
179 views
Hi, I need to display a total count per series in a note at end of bar per attachment.  The attachment is a screenshot of equivalent functionality in Telerik UI for AJAX page that I am converting over to MVC.

Chart syntax at moment:
​
@(Html.Kendo().Chart()
    .Name(Model.ChartName)
    .Title(title => title
        .Text(Model.ChartTitle)
        .Align(ChartTextAlignment.Left)
    )
    .HtmlAttributes(new { @class = "dashboardChart" })
    .Legend(legend => legend
        .Visible(Model.LegendVisible)
        .Position(ChartLegendPosition.Right)
    )
    .Series(series =>
    {
        series.Bar(new double[] { Model.AgedCount }).Name(Model.ChartAgedSeriesTitle).Color(myapp.Controllers.DashboardController.ChartSeries1Color);
        series.Bar(new double[] { Model.UnAgedCount }).Name(Model.ChartUnAgedSeriesTitle).Color(myapp.Controllers.DashboardController.ChartSeries2Color);
    })
    .ValueAxis(axis => axis.Numeric()
        .MinorUnit(1)
        .MajorUnit(Model.ChartMaxValue <= 10 ? 1 : 5)
        .Min(0)
        .Max(Model.ChartMaxValue)
        .MajorGridLines(lines => lines.Visible(true))
        .MinorGridLines(lines => lines.Visible(true))
        .Visible(true)
        .Labels(labels => labels.Visible(true))
        .MinorTicks(ticks => ticks.Visible(true))
    )
    .Tooltip(tooltip => tooltip
            .Visible(true)
    )
    .Events(events => events
                .SeriesClick("onSeriesClick")
            )
)
Doug
Top achievements
Rank 1
Veteran
 answered on 07 Aug 2016
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?