Telerik Forums
UI for ASP.NET MVC Forum
1 answer
532 views

Hello,

I understand that ClientTemplate does not work within A server bound grid, I was curious as to how would you be able to create a conditional statement such as 

                    .ClientTemplate(
                        "# if (tmpIsActive && Active == 1) { # " +
                        "Sales" +
                        " # } else if (tmpIsActive && Active == 2) { # " +
                        "Corp" +
                        "# } #"
                    )

to be used on a server bound grid.

Thanks,

Joel

 

Georgi
Telerik team
 answered on 20 Mar 2019
8 answers
685 views

Hi, I've a page with 2 grids. Both of them has buttons to add elements, moreover I can pass data from one to the other. The problem that I've is that the grids  data it's not reloaded. Once I try to reload the grids get empty and the function to load the data in the controller it's not called, also the code is showing I'm passing throught the dataSource.read(), the console.logs() are printed correctly. This was working 5 days ago, since then any change has been done on the cshtml and on the controller files.

Any help will be appreciated. 

Thanks in advance.

These are my functions to reload the grids (javascript)

**************************************************************************************************

function reloadOrigenDestino(reloadALL = false) {
        if (esOrigen == true || esOrigen == 'True' || reloadALL ) reload(true);
        if (esOrigen == false || esOrigen == 'False' || reloadALL ) reload(false);
    }

 function reload(_esOrigen) {
        if (_esOrigen) {
            console.log('**** reload es origen');
            $("#listaOrigen").data("kendoGrid").dataSource.read();
        }
        else {
            console.log('*** reload es destino');
            $("#listaDestino").data("kendoGrid").dataSource.read();
        }
    }

**************************************************************************************************

This is my html whith the 2 grids (both of them with different ids)

*************************************************************************************************

     <!-- ************** GRID ORIGEN************** -->

    <div class="bt_col_4">
        <h3>@Estudios.labelForOrigen</h3>

        @(Html.Kendo().Grid<Bogem.Areas.Estudios.Models.EstudiosOrigenDestinoVM>()
                              .Name("listaOrigen")
                              .Columns(columns =>
                              {
                                  columns.Bound(c => c.IdOrigenDestino).Hidden(true);
                                  columns.Bound(c => c.EsOrigen).Hidden(true);
                                  columns.Bound(c => c.CodigoPostal).Visible(true);
                                  columns.Bound(c => c.Poblacion).Visible(true);
                                  columns.Bound(c => c.Alias).Visible(true);
                                  columns.Bound(c => c.Punto).Visible(true);
                                  columns.Bound(o => o.IdOrigenDestino).Title(Resources.Editar).Width(45).MinResizableWidth(45).Sortable(false).Filterable(false)
                                                                       .ClientTemplate("<a href='javascript:(showAddEditOrigenDestino(#= IdOrigenDestino #, #= EsOrigen #));'><i class='k-icon k-i-edit k-icon-22'></i></a>")
                                                                       .HtmlAttributes(new { style = "text-align: center" })
                                                                       .Visible((bool)ViewData["canEdit"]).ToString();
                                  columns.Bound(o => o.IdOrigenDestino).Title(Resources.Eliminar).Width(45).MinResizableWidth(45).Sortable(false).Filterable(false)
                                                                       .ClientTemplate("<a href='javascript:(showDialogDeleteOrigenDestino(#= IdOrigenDestino #, #= EsOrigen #));'><i class='k-icon k-i-trash k-icon-22'></i></a>")
                                                                       .HtmlAttributes(new { style = "text-align: center" })
                                                                       .Visible((bool)ViewData["canDelete"]).ToString();
                              })
                              .ToolBar(toolbar =>
                              {
                                  if ((bool)ViewData["canAdd"]) toolbar.Custom().IconClass("k-icon k-i-add k-icon-22").Text(Estudios.titleForAddOrigen).Url("#").HtmlAttributes(new { onclick = "showAddEditOrigenDestino(-1, '" + true + "');" });
                              })
                              .HtmlAttributes(new { style = "text-align: right" })
                              .Sortable(sortable =>
                              {
                                  sortable.SortMode(GridSortMode.MultipleColumn);
                              })
                              .Filterable(filterable => filterable
                                  .Extra(false)
                                  .Operators(operators => operators
                                      .ForString(str => str.Clear()
                                          .Contains(Resources.filtroContains)
                                          .IsEqualTo(Resources.filtroEqualTo)
                                          .IsNotEqualTo(Resources.filtroNotEqualTo)
                                      )
                                  )
                              )
                              .Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
                              .Editable(edit => edit.Mode(GridEditMode.PopUp))
                              .Scrollable()
                              .Resizable(resize => resize.Columns(true))
                              .DataSource(dataSource => dataSource
                              .Ajax()
                              .Model(model => model.Id(p => p.IdOrigenDestino))
                              .Read(read => read.Action("CargaListadoNuevo", "OrigenDestino", new { esOrigen = true }))
                              )
        )

    </div>

     <!-- ************** GRID DESTINO ************** -->

    <div class="bt_col_4">
        <h3>@Estudios.labelForDestino</h3>

        @(Html.Kendo().Grid<Bogem.Areas.Estudios.Models.EstudiosOrigenDestinoVM>()
                              .Name("listaDestino")
                              .Columns(columns =>
                              {
                                  columns.Bound(c => c.IdOrigenDestino).Visible(false);
                                  columns.Bound(c => c.EsOrigen).Visible(false);
                                  columns.Bound(c => c.CodigoPostal).Visible(true);
                                  columns.Bound(c => c.Poblacion).Visible(true);
                                  columns.Bound(c => c.Alias).Visible(true);
                                  columns.Bound(c => c.Punto).Visible(true);
                                  columns.Bound(o => o.IdOrigenDestino).Title(Resources.Editar).Width(45).MinResizableWidth(45).Sortable(false).Filterable(false)
                                                                       .ClientTemplate("<a href='javascript:(showAddEditOrigenDestino(#= IdOrigenDestino #, #= EsOrigen #));'><i class='k-icon k-i-edit k-icon-22'></i></a>")
                                                                       .HtmlAttributes(new { style = "text-align: center" })
                                                                       .Visible((bool)ViewData["canEdit"]).ToString();
                                  columns.Bound(o => o.IdOrigenDestino).Title(Resources.Eliminar).Width(45).MinResizableWidth(45).Sortable(false).Filterable(false)
                                                                       .ClientTemplate("<a href='javascript:(showDialogDeleteOrigenDestino(#= IdOrigenDestino #, #= EsOrigen #));'><i class='k-icon k-i-trash k-icon-22'></i></a>")
                                                                       .HtmlAttributes(new { style = "text-align: center" })
                                                                       .Visible((bool)ViewData["canDelete"]).ToString();
                              })
                              .ToolBar(toolbar =>
                              {
                                  if ((bool)ViewData["canAdd"]) toolbar.Custom().IconClass("k-icon k-i-add k-icon-22").Text(Estudios.titleForAddOrigen).Url("#").HtmlAttributes(new { onclick = "showAddEditOrigenDestino(-1, '" + false + "');" });
                              })
                              .HtmlAttributes(new { style = "text-align: right" })
                              .Sortable(sortable =>
                              {
                                  sortable.SortMode(GridSortMode.MultipleColumn);
                              })
                              .Filterable(filterable => filterable
                                  .Extra(false)
                                  .Operators(operators => operators
                                      .ForString(str => str.Clear()
                                          .Contains(Resources.filtroContains)
                                          .IsEqualTo(Resources.filtroEqualTo)
                                          .IsNotEqualTo(Resources.filtroNotEqualTo)
                                      )
                                  )
                              )
                              .Editable(edit => edit.Mode(GridEditMode.PopUp))
                              .Scrollable()
                              .Resizable(resize => resize.Columns(true))
                              .DataSource(dataSource => dataSource
                              .Ajax()
                              .Model(model => model.Id(p => p.IdOrigenDestino))
                              .Read(read => read.Action("CargaListadoNuevo", "OrigenDestino", new { esOrigen = false }))
                              )

        )

    </div>

 

**************************************************************************************************
My read function from server
*************************************************************************************************

        [BogemAuthorization(Option = OpcionesModulo.ESTU_G_ORGDEST, NivelAcceso = new TipoAcceso[] { TipoAcceso.Lectura })]
        public ActionResult CargaListado([DataSourceRequest]DataSourceRequest request, bool esOrigen)
        {
            List<EstudiosOrigenDestinoBO> estudios = new List<EstudiosOrigenDestinoBO>();

            if (esOrigen) estudios = _origenDestinoBL.GetOrigenes(GetCurrentEstudio()).ToList().Where(x => x.IdSysState == (int)SystemState.Active).ToList();
            else estudios = _origenDestinoBL.GetDestinos(GetCurrentEstudio()).ToList().Where(x => x.IdSysState == (int)SystemState.Active).ToList();

            foreach (EstudiosOrigenDestinoBO item in estudios)
            {
                item.Poblacion = _poblacionBL.GetPoblacion(item.IdPoblacion).Poblacion;
                item.CodigoPostal = _codigoPostalBL.GetCodigoPostal(item.IdCP).CP;
            }

            DataSourceResult result = estudios.ToDataSourceResult(request, _estudios => new
            {
                IdOrigenDestino = _estudios.IdOrigenDestino,
                IdEstudio = _estudios.IdEstudio,
                EsOrigen = _estudios.EsOrigen,
                IdCP = _estudios.IdCP,
                IdPoblacion = _estudios.IdPoblacion,
                Alias = _estudios.Alias,
                Punto = _estudios.Punto,
                IdSysState = _estudios.IdSysState,
                CodigoPostal = _estudios.CodigoPostal,
                Poblacion = _estudios.Poblacion
            });

            return Json(result);
        }

Alex Hajigeorgieva
Telerik team
 answered on 19 Mar 2019
10 answers
1.6K+ views

Currently I have a grid that uses a helper to specify the attributes:

.Filterable(f => f
.Extra(false)
.Operators(o => o
.ForString(str => str
.Clear()
.Contains("Contains")
.StartsWith("Starts with")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
)
.ForNumber(num => num
.Clear()
.IsEqualTo("Is equal to")
.IsGreaterThan("Is greater than")
.IsLessThan("Is less than")
)
)

The filterable data in the grid is encoded, s. o 'a b' is stored as 'a%20b'. I would like to build a custom filter using the helpers that allows the user to filter on 'a b'?

 

Tsvetina
Telerik team
 answered on 19 Mar 2019
3 answers
114 views

    Serverbound grid

  • Trying to get the multicheckbox filter to work correctly
  • Additionally would like to be able to have a search function
  • Similar to the ajax multicheckbox filter: https://demos.telerik.com/aspnet-mvc/grid/filter-multi-checkboxes

    Problem:
  • While doing a serverbound grid, it seems that .Filterable(ftb => ftb.Multi(true).Search(true)) does not work
  • When clicking on the filter icon, it causes the application to do a server call via an anchor link, so it does not allow the user to use the multi-checkbox filter
Konstantin Dikov
Telerik team
 answered on 19 Mar 2019
2 answers
90 views

Noticed that when we create an item in the Scheduler and check the All Day checkbox the resulting Recurrence Rule adds an extra day. This leads to an extra day showing up in the Scheduler interface. We don't set any specific timezone on the scheduler, we actually hide all the timezone options in the interface as it just confuses our users:

        //hide the timezone selections
        e.container.find("[data-role=timezoneeditor]").hide();
        e.container.find("[data-role=timezoneeditor]").parent('div').hide();
        $('label[for="StartTimezone"]').hide();
        $('label[for="StartTimezone"]').parent('div').hide();
        e.container.find("label[for='EndTimezone']").hide();
        e.container.find("label[for='EndTimezone']").parent('div').hide();

For example I create an event that starts on March 28, 2019, repeats daily and ends on Mar 30 3019 and check "All Day" checkbox - the resulting recurrence rule is saved as FREQ=DAILY;UNTIL=20190331T025959Z. In the scheduler we see the event on the 31st of March.

I can send you the code we have for the CustomEditortemplate.cshtml. The clocks moved forward an hour this month (now Atlantic Daylight Time ADT) if that provides a clue, can't be assured if this was happening before the time change or not though...

Also start and end times are saved as 2019-03-28 00:00:00.000 - zeros for the time portion in our SQL Server - when I look at the models in EventSchedule_Create([DataSourceRequest] DataSourceRequest request, IEnumerable<EventScheduleViewModel> models) the start time and end time are 12:00:00 AM so this might be Entity Framework or SQL server ?

 

Simon
Top achievements
Rank 1
 answered on 18 Mar 2019
4 answers
1.6K+ views

I have a Kendo ListBox that I need to set a single item selected through a JavaScript function. I know both the text and value that I want to set, but can't figure out how. Any help appreciated!

Steve.

Steve
Top achievements
Rank 1
 answered on 18 Mar 2019
9 answers
532 views

I have 3 questions this time.

 

1) After some fiddling around I got my responsive panel working.  I then went and changed my default layout so that I have the content in div in the middle of the form, rather than all left aligned.  When I made the change the panel no longer hides.  Instead when it should be 'hidden' it is visible but on the left outside edge of the div.  When I click the button to make it appear it slides into the div correctly and appears where it should.  What do I need to do to get it to be hidden and not just on the outside of the div?

2) In my HTML I had the following button

<button name="Logout" tag="span" class="textButton" type="submit">Logout</button>

I thought it would be a simple change to make it a Kendo button:

<kendo-button name="Logout" tag="span" class="textButton" type="submit">Logout</kendo-button>

 

However once I did this, it no longer worked. I am sure it is something simple, but what did I miss?

 

3) The final question is a general use question.  My app will be in ASP Core.  I see a lot of examples that use the format of:

<kendo-object></kendo-object>

and some that are in the format of:

@(Html.Kendo().Object()
)

 

Which one is the 'correct' format?  Are there advantages to using one over the other?  If I use the 2nd option will all of my themes still apply to the objects?

Dimitar
Telerik team
 answered on 18 Mar 2019
3 answers
1.1K+ views

Hello,

I'm using Kendo grid (and other components) through the MVC wrapper. Recently, I started using sorting and filtering, in the following way:

.DataSource(dataSource => dataSource.Ajax()

.Read(read => read.Action(action name, controller name)

.Sort(blah blah)

.Filter(blah blah)

)

All sort/filter operations are server-side. (obviously, I'm not going to dump a million records into the browser and have javascript filter them...)

Questions:

1) Sort and Filter MVC calls take the view model fields, which eventually fill the DataSourceRequest. How exactly does that translate through the dynamic linq into sql? Does it rely on the assumption that the name of the field in the view model will be the same as in the data model?

I mean, if I use something like

dataSource.Filter(filter => filter.Add(viewModel => viewModel.MachineId).IsEqualTo(machineId));

and later the request object (with field names as strings) with those filters, sorts etc goes into .ToDataSourceResult(),

how does it know which field in the data model - in the Entity Framework entity, that is - does the viewModel.MachineId map to?

For myself, I use AutoMapper, so through the mapper configuration, I know which field is which... but Kendo MVC side doesn't have that knowledge.

And if it makes an assumption about data model and view model field names being the same, how do I pass it the actual data model field name in cases when they aren't the same?

 

2) Is there any advantage to using extra parameters in the controller call, to filter the data, versus using Filter(), so that all the filtering info ends up in one and the same object, the DataSourceRequest?

If I add extra parameters to the controller call, I need to implement a separate controller call for each combination of parameters. And, in each call, I have to add all the sql conditions myself. If I can just use Filter() in the grid definition, I can keep reusing the same controller call for all combinations.

And, theoretically, through dynamic linq, when the data request object is passed into .ToDataSourceResult, this should result in all the "where" conditions being correctly applied, and the filtering performed in sql, on the sql server side... or am I wrong here?

Yet, your code samples with master/detail grids (a master grid with a detail template which contains another grid) used a separate controller call with the parameter; is there a reason for it, if it could have been simply filtered by this field?

 

3) How would I use Filter() in a grid / data source defined in the detail template of another grid?

The problem here is that related operators, such as IsEqualTo(), expect me to know the value on the server side, at the time C# is executed.

However, in a grid detail template, for the detail grid construction, this value is only known on the client side.

A call like .IsEqualTo("#=template_field_here#")) won't work; the argument is obviously a string, yet the .IsEqualTo expects the argument to be of the same type as the field I'm filtering... which makes sense only if I knew it on the server, outside of the detail template.

Would I have to write the whole detail grid in jquery?

 

(Yes, I could - and I did - write a separate controller call, with extra parameters, to accomplish this; I'm just trying to remove that code, if I really don't have to do it that way... if it can work simply through filters in the DataSourceRequest)

 

 

 

Konstantin Dikov
Telerik team
 answered on 18 Mar 2019
1 answer
173 views

Wondering if you have code samples regarding validating different sections of the recurrence editor. For instance if the user selects a daily recurrence then deletes (using keyboard) the value in the "After" spinner or the "On" date/time picker. Or they do something similar with a Weekly recurrence and perhaps check none of "Repeat on" checkboxes and delete values for "After" or "On". 

I see there is some reasonable default saved for RecurrenceRule in the database - is that by design as a way to avoid exhaustive validation? I can see this being a difficult ask, but it only takes one user to enter a recurring event incorrectly and it leads to a lot of confusion and questions. Is this a validation rabbit hole best avoided?

 

Ianko
Telerik team
 answered on 15 Mar 2019
1 answer
127 views

For my data in the following class:

public class MyModel
{
    public double Value { get; set; }
    public DateTime Date { get; set; }
}

I have a chart with the following configuration:

@(Html.Kendo().Chart<MyModel>()
    .Name("MyChart")
    .Series(series =>
    {
        series.ScatterLine(MyIEnumerableData)
            .Fields("Date", "Value")
            .Style(ChartScatterLineStyle.Smooth)
            .Markers(m => m.Visible(false))
            .Highlight(h => h.Visible(false))
            .Labels(false)
            .Name("Series1");
    })
    .XAxis(x => x
        .Date()
        .Title(title => title.Text("Date"))
    )
    .YAxis(y => y
        .Numeric()
        .Title(title => title.Text("Value"))
    )
)

The axis range is correct, but the line is not displayed.

Examining the data contained in the widget on the page, the Date field is populated with (example): "/Date(1156934074549)/" instead of correctly-formed datetimes.

If I change my model to use a string instead of a datetime, and convert the datetime with .toString("yyyy-MM-dd HH:mm:ss"), the kendo widget appears to understand the data correctly, and it draws the line. This is fine as a workaround, but I should not need to convert the data like this.

Why does the kendo widget not understand datetime data? There is no override when specifying the fields to indicate the data type, and there is no method in the series definition to do this, either.

Tsvetina
Telerik team
 answered on 15 Mar 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?