Telerik Forums
UI for ASP.NET MVC Forum
3 answers
136 views
Hi

I have implemented below custom validation rule. It works but it triggers a controller method twice once on Edit of cell and once Closure of cell. I just wanted it to be triggered on closure of cell. Can you please help me on this. Thank you

My property in in my Model is as below

 [Remote("IsUniqueDisplayName", "Bookmark", AdditionalFields = "DocumentTypeId", ErrorMessage = "Display Name must be Unique.")]
 public string DocumentTypeSortNameTitle { get; set; }

Custom validation rule implementation in javascript as below

 (function ($, kendo) {
        $.extend(true, kendo.ui.validator, {
            rules: {
                mvcremotevalidation: function (input) {
                    if (input.is("[data-val-remote]") && input.val() != "") {
                        var remoteURL = input.attr("data-val-remote-url");
                        var valid = true;
                        var td = input.parent('td');
                        if (td.hasClass("k-dirty-cell")) {
                            var found = false;
                            $.ajax({
                                async: false,
                                url: remoteURL,
                                type: "GET",
                                dataType: "json",
                                data: validationData(input, this.element),
                                success: function (result) {
                                    found = result;
                                    if (found)
                                        valid = false;
                                    else {
                                        valid = true;
                                    }
                                },
                                error: function () {
                                    valid = false;
                                }
                            });
                        }
                       return valid;
                      
                    }

                    return true;
                }
            },
            messages: {
                mvcremotevalidation: function (input) {
                     return input.attr("data-val-remote");
                  //  return "Display Name must be Unique";
                }
            }
        });

        function validationData(input, context) {
            var grid = $("#BookmarkDoctypeGrid").data("kendoGrid");
            var currentData = grid.dataSource.data();
            var uid = $("#BookmarkDoctypeGrid").find('.k-edit-cell').parent('tr').data('uid');
            var dataItem = grid.dataSource.getByUid(uid);
            var documentTypeId = dataItem.DocumentTypeId;
            var fields = input.attr("data-val-remote-additionalFields").split(",");
            var name = input.prop("name");
            var prefix = name.substr(0, name.lastIndexOf(".") + 1);
            var fieldName;
            var data = {};
            for (var i = 0; i < fields.length; i++) {
                fieldName = fields[i].replace("*.", prefix);
                if (fieldName == 'DocumentTypeId') {
                    data[fieldName] = documentTypeId;
                } else
                    {
                    data[fieldName] = $("[name='" + fieldName + "']", context).val();
                }
            }            
            return data;
        }
    })(jQuery, kendo);
Petur Subev
Telerik team
 answered on 01 Apr 2015
1 answer
709 views
Hi,


I have a dropdown list binding to a datasource with duplicate records. Is there any way I  can remove the duplicate items in the dropdown list? I don't want to remove the duplicate records in the datasource because it is shared by a grid. Thanks.
Georgi Krustev
Telerik team
 answered on 01 Apr 2015
5 answers
1.1K+ views
I have wired up a simple grid with some bound columns and one of those columns I'm trying to create a hyperlink.  Here is my code:

@(Html.Kendo().Grid(Model.CareAlerts)
    .Name("Alerts")
    .Columns(columns =>
    {
        columns.Bound(p => p.AlertDate).Title("Date").Format("{0:d}");
        columns.Bound(p => p.PatientName).Template(@<text>
            @Html.ActionLink(@item.PatientName, "Member", new { id = @item.PatientASID })
        </text>);
        columns.Bound(p => p.AlertSummary).Title("Message");
    })
                                        .Sortable()
                                        .DataSource(dataSource => dataSource
                                                .Ajax()
                                                .PageSize(20)
                                                .ServerOperation(false)
                                             )
            )

The second column is the column where I'm attempting to show the hyperlink.  Now, when I render the page, I can see the hyperlink for a split second before it disappears and I just see the text is supposed to be included in the link, but it is not linked after that.

Now, here's the funny thing:  If I remove the reference to kendo.aspnetmvc.min.js in my BundleConfig.cs file, the hyperlinks show up just fine, however, I get a "Script not included" error if I do this.

Any idea what I'm doing wrong?
Dimiter Madjarov
Telerik team
 answered on 31 Mar 2015
2 answers
133 views
Is anyone else having issues with the standard filtering functionality on a ForeignKey column with the latest release?  After upgrading, I noticed in a project of mine the Filter button was not causing a datasource read, and also went to the demo page (http://demos.telerik.com/aspnet-mvc/grid/foreignkeycolumn) and was getting the same behavior across different browsers (no sign of any Javascript errors in various browser debuggers).

From that demo page, if I go to filter the Category column on "Beverages", no filter event seems to fire.  However, if I go to the the Unit Price column and hit the "Clear" button and then go back to the Category column and filter on "Beverages" again, it properly filters.

Seems to affect the Kendo UI version of the demo the same way from what I can see

Regards,
Toby
Atanas Georgiev
Telerik team
 answered on 31 Mar 2015
3 answers
193 views
How can I designate route based on marker list and show route on map? At now I have only added markes.

Code form my View:
@(Html.Kendo().Map()
    .Name("Bing")
    .Center(53.4252981, 14.5526117)
    .Zoom(12)
    .Layers(layers =>
    {
        layers.Add()
            .Type(MapLayerType.Bing)
            .ImagerySet(MapLayersImagerySet.Road)           
            .Key("key");
        layers.Add()
            .Type(MapLayerType.Marker)
            .DataSource(dataSource => dataSource
                  .Read(read => read.Action("_StoreLocations", "Home"))
            )
            .LocationField("LatLng")
            .TitleField("Title");
        layers.Add()
            .Type(MapLayerType.Shape)
            .DataSource(dataSource => dataSource
                  .Read(read => read.Action("_StoreLocations", "Home"))
            )
            .LocationField("LatLng")
            .TitleField("Title");
    })
)

Best regards,
Michał
T. Tsonev
Telerik team
 answered on 31 Mar 2015
7 answers
2.8K+ views
Is there a way to only allow the user to control the selectable file types?

I know I can get the information once they select the file but I'd prefer to filter the list to only .pdf, or whatever.
Dimiter Madjarov
Telerik team
 answered on 31 Mar 2015
3 answers
124 views
I have issues in using the spinners of numeric textbox in IE10(Standards mode as well as compatiblity mode)
but this doesn't work in the demo site either

http://demos.telerik.com/aspnet-mvc/numerictextbox/index

Any workarounds for this ?


Kiril Nikolov
Telerik team
 answered on 31 Mar 2015
1 answer
369 views
I have a form that has a standard datepicker that highlights specific dates.  Based on the example in the demo section, this is what the control is set up as:
@(Html.Kendo().DatePicker()
      .Name("datepicker")
      .Value(DateTime.Today)
      .HtmlAttributes(new {style = "width: 100%;"})
      .Footer("Today - #=kendo.toString(data, 'd') #")
      .MonthTemplate("# if ($.inArray(+data.date, events) != -1) { #" +
                     "<div class='" +
                     "# if (data.value > 0) { #" +
                     "order" +
                     "# } #" +
                     "'>#= data.value #</div>" +
                     "# } else { #" +
                     "#= data.value #" +
                     "# } #"))

In the Javascript, I have this:

var today = new Date(),
    events = [];
 
$.ajax({
    url: "GetOrderDates?shipOrderNbr=" + $("#shiporder").val(),
    dataType: "json",
    success: function (result) {
        events = []; //clear the array of any preexisting dates that may have been loaded
        $.each(result, function (index, value) {
            events.push(new Date(value)); //01/01/2015, etc
         }); 
     }
});

The above code works; the ajax call returns a collection of strings that are all parsed into date objects and pushed in the the events array.

However, at any given time, the collection of dates can change depending on the users input.  However, once the datepicker control is initialized, changing the dates array doesn't refresh the highlighted dates in the control (in effect, once the MonthTemplate is rendered, it never reloads).

Is there a way to dynamically change the highlighted dates client side?
Daniel
Telerik team
 answered on 30 Mar 2015
1 answer
200 views
Hello Telerik Team,

I want my kendo grid built in Asp.Net MVC 4 receive any object model, in other words, dynamic. The action method of my controller not show errors, but the data not displayed in kendo grid. Any suggestions?

View:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
 <% Html.Kendo().Grid<dynamic>()
    .Name("GridTeste")
    .Columns(columns =>
    {
        if (Model != null)
        {
            foreach (var x in Model)
            {
                 columns.Bound(x.Value, x.Key.ToString()).Title(x.Key).Encoded(false);
            }
        }
    }
    )
         .DataSource(datasource => datasource
         .Ajax()
         .Read(read => read.Action("CarregarDados", "ImportacaoTabelaPropria", new { acao = "Brasindice", ajuste = "", nova_validade = "" }))
         )
        .Navigatable()
        .Scrollable()
        .Selectable()
        .HtmlAttributes(new { style = "width:100%;height:400px;", id = "GridTeste" })
        .Render();
 %>

My Action in Controller: 

        public ActionResult CarregarDados(string acao, string ajuste, string nova_validade, [DataSourceRequest] DataSourceRequest request)
        {
            PreencherTabelaPropria tabela_propria = new PreencherTabelaPropria();
            PreencherBrasindice bras = new PreencherBrasindice();
            Dictionary<string,System.Type> colunas = new Dictionary<string,Type>();
            if (acao.Equals("Tabela propria"))
            {
                return Json(tabela_propria.PreencherTabelaPropriaValores(), JsonRequestBehavior.AllowGet);
            }
            if (acao.Equals("Brasindice"))
            {
                if (bancoBrasindice != null)
                {
                    if (!String.IsNullOrEmpty(ajuste))
                    {
                        foreach (var x in bancoBrasindice)
                        {
                            x.Ajuste_liberado = ajuste;
                            if (!String.IsNullOrEmpty(nova_validade))
                                x.Nova_validade = DateTime.Parse(nova_validade);
                        }
                        return Json(bancoBrasindice, JsonRequestBehavior.AllowGet);
                    }
                }
                else
                {
                    List<ImportacaoBrasindiceModel> brasindice = bras.PreencherBrasindiceValores();
                    //atualizar o modelo com os valores de ajuste e validade
                    foreach (var x in brasindice)
                    {
                        x.Ajuste_liberado = ajuste;
                        if (!String.IsNullOrEmpty(nova_validade))
                            x.Nova_validade = DateTime.Parse(nova_validade);
                    }
                    bancoBrasindice = brasindice;
                }
                Dictionary<string, System.Type> colunas2;
                PropertyInfo[] propriedades = typeof(ImportacaoBrasindiceModel).GetProperties();
                colunas2 = new Dictionary<string, Type>();
                foreach (PropertyInfo x in propriedades)
                {
                    colunas.Add(x.Name, x.PropertyType);
                }
                //return PartialView("~/Views/ImportacaoTabelaPropria/TesteGridParcial.ascx", Json(bancoBrasindice, JsonRequestBehavior.AllowGet));
                return Json(bancoBrasindice.ToDataSourceResult(request), RenderPartialViewToString("~/Views/ImportacaoTabelaPropria/TesteGridParcial.ascx", colunas), JsonRequestBehavior.AllowGet);

            }
            return Content("");
        }

My method to convert Partial View to string: 

protected string RenderPartialViewToString(string viewName, object model)
        {
            if (string.IsNullOrEmpty(viewName))
                viewName = ControllerContext.RouteData.GetRequiredString("action");

            ViewData.Model = model;

            using (StringWriter sw = new StringWriter())
            {
                ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
                ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);

                return sw.GetStringBuilder().ToString();
            }
        }


















Daniel
Telerik team
 answered on 30 Mar 2015
3 answers
118 views
I am using kendo color picker and its doesn't work fine in IE10(standard mode as well as compatibility mode)

I later found this issue in demo either
http://demos.telerik.com/aspnet-mvc/colorpicker/index 

I am not able to select any color from the color picker in IE10

I am using win 7 64 bit environment.
Any workaround for this ?
Dimiter Madjarov
Telerik team
 answered on 30 Mar 2015
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
Upload
ComboBox
MultiSelect
ListView
Window
TabStrip
Menu
Installer and VS Extensions
Spreadsheet
AutoComplete
TreeList
Gantt
PanelBar
NumericTextBox
Filter
ToolTip
Map
Diagram
Button
PivotGrid
Form
ListBox
Splitter
Application
FileManager
Sortable
Calendar
View
MaskedTextBox
PDFViewer
TextBox
Toolbar
MultiColumnComboBox
Dialog
DropDownTree
Checkbox
Slider
Switch
Notification
ListView (Mobile)
Pager
Accessibility
ColorPicker
DateRangePicker
Wizard
Security
Styling
Chat
MediaPlayer
TileLayout
DateInput
Drawer
SplitView
Template
Barcode
ButtonGroup (Mobile)
Drawer (Mobile)
ImageEditor
RadioGroup
Sparkline
Stepper
TabStrip (Mobile)
GridLayout
Badge
LinearGauge
ModalView
ResponsivePanel
TextArea
Breadcrumb
ExpansionPanel
Licensing
Rating
ScrollView
ButtonGroup
CheckBoxGroup
NavBar
ProgressBar
QRCode
RadioButton
Scroller
Timeline
TreeMap
TaskBoard
OrgChart
Captcha
ActionSheet
Signature
DateTimePicker
AppBar
BottomNavigation
Card
FloatingActionButton
Localization
MultiViewCalendar
PopOver (Mobile)
Ripple
ScrollView (Mobile)
Switch (Mobile)
PivotGridV2
FlatColorPicker
ColorPalette
DropDownButton
AIPrompt
PropertyGrid
ActionSheet (Mobile)
BulletGraph
Button (Mobile)
Collapsible
Loader
CircularGauge
SkeletonContainer
Popover
HeatMap
Avatar
ColorGradient
CircularProgressBar
SplitButton
StackLayout
TimeDurationPicker
Chip
ChipList
DockManager
ToggleButton
Sankey
OTPInput
ChartWizard
SpeechToTextButton
InlineAIPrompt
TimePicker
StockChart
RadialGauge
ContextMenu
ArcGauge
AICodingAssistant
+? more
Top users last month
Top achievements
Rank 1
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ivory
Top achievements
Rank 1
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
YF
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Top achievements
Rank 1
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ivory
Top achievements
Rank 1
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
YF
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?