Telerik Forums
UI for ASP.NET MVC Forum
1 answer
221 views
I have a grid(see below) with specified widths for the columns.  Once the page starts to render the widths are correct; as soon as the grid is databound it auto generates widths for the columns.  The issue is that these new widths are nothing like what I have specified.  Any ideas?

 <%= Html.Telerik().Grid<WebUI.Models.UserMaintenance>()    
    .Name("CheckedUsers")
    .DataKeys(keys => 
    { 
        keys.Add(u => u.Id); 
    })      
    .Columns(columns =>        
    {
        //columns.Bound(u => u.Id).Hidden(true);
        //columns.Bound(u => u.Name).Width(350);
        columns.Bound(item => item.UserId).Title("User Id").Width(5);
        columns.Bound(item => item.FirstName).Title("First Name").Width(15);
        columns.Bound(item => item.LastName).Title("Last Name").Width(15);
        columns.Bound(item => item.OrgName).Title("Org Name").Width(25);
        columns.Bound(item => item.Email).Title("Email Address").Width(20);
        columns.Bound(item => item.Language).Title("Language").ReadOnly().Width(10);
        columns.Bound(item => item.ApplicationAssigned).Title("Applications").ReadOnly().Width(15);
        columns.Bound(item => item.ComplianceAssigned).Title("Compliance").ReadOnly().Width(51);
        columns.Bound(item => item.UserType).Title("User Type").ReadOnly().Width(15);
        columns.Bound(item => item.LastActivityDate).Title("Last Sign In").ReadOnly().Width(15);
        columns.Bound(item => item.LockedOut).Title("Locked Out").ReadOnly().Width(5);
        columns.Command(commands =>
            {
                commands.Custom("unlock").Text("Unlock").Ajax(true);
            }
            ).Title("Unlock User").Width(5);
        columns.Command(commands =>
        {
            commands.Edit().ButtonType(GridButtonType.Image);
            commands.Delete().ButtonType(GridButtonType.Image);
        }).Width(5);
       
    })
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .Filterable()
    .Sortable()
           //.ClientEvents(clientEvents => clientEvents.OnDataBinding("onDataBinding").OnDelete("onCheckedUsersDelete").OnError("onCheckedUsersError"))
    .ClientEvents(clientEvents => clientEvents.OnDelete("onCheckedUsersDelete").OnError("onCheckedUsersError").OnSave("onCheckedUsersSave").OnCommand("onCheckedUsersCommand"))
    .DataBinding(dataBinding => dataBinding.Ajax().Select("_GetAllMembershipUser", "Survey")
                                                    .Delete("_DeleteMembershipAssigned", "Survey")
                                                    .Update("_EditMembershipUser","Survey"))
    .HtmlAttributes(new { style = "min-width:1500px" })

    %>
Dimiter Madjarov
Telerik team
 answered on 04 Nov 2014
1 answer
951 views
OK it seems to me that this should be a simple thing but for some reason it is not documented anywhere (at least I can't find it).
Using:
http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/menu/overview#bind-kendo-menu-to-a-hierarchical-model

I have a working menu EXCEPT hyper links

Sure I can get it to fire the select event. What exact is being passed in. I can't get the values I set on the "item" object (Text or Url).

What are the available properties for the "item" object in the above example?

All I need to do is make the select function redirect to a new page. I would think that this is what 99% of your users would want to do. Why is an end-to-end example of a hierarchical model with hyperlinks not given?

Please provide this.

@(Html.Kendo().Menu()
.Name("adminMenu") //The name of the menu is mandatory. It specifies the "id" attribute of the widget.
.BindTo(Model, mappings =>
{
mappings.For<McGladrey.DOTT.DataModel.DOTTCustom.sp_GetUserTreeData_Result>(binding => binding //define first level of menu
.ItemDataBound((item, parent) => //define mapping between menu item properties and the model properties
{
item.Text = parent.NodeName;
})
.Children(parent => parent.ChildrenNodes)
); //define which property of the model contains the children
mappings.For<McGladrey.DOTT.DataModel.DOTTCustom.sp_GetUserTreeData_Result>(binding => binding
.ItemDataBound((item, child) =>
{
item.Text = child.NodeName;
item.Url = child.NodeAction;

}));
})
.Events(e=>e.Select("MenuSelected"))
.Orientation(MenuOrientation.Vertical)
)

<script type="text/javascript">

function MenuSelected(e)
{
alert(e.item.Text + " " + e.item.Url);

}
</script>

-Martin
Petur Subev
Telerik team
 answered on 03 Nov 2014
1 answer
163 views

I have a Kendo grid :        

@(Html.Kendo().Grid<MyVm>().Name("grid").Columns(columns =>
      ...
    .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model => model.Id(p => p.Id))
            .Read(read => read.Action("List", "MyController", new { id = Model.Id }).Type(HttpVerbs.Get)))

On my controller I have :   

public JsonResult List([DataSourceRequest] DataSourceRequest request, int id)
    {
         //if (FIRST/INITIAL LOADING) ?????
         ...
    }

How can I check on controller if its the initial loading/binding?

Thanks
Nikolay Rusev
Telerik team
 answered on 03 Nov 2014
1 answer
195 views
Hi Guys,

I have built a WebAPI for user login, the webAPI can generate Access Token, if the user provided correct UserName and password. My Question is how I can pass user role information to the MVC application also.

For example,

I have a MVC app controller below, how can I pass the role 'Admin, UserEditor' from the Web API? I know I can use another WebAPI call to check user role, but it is not a good idea to do it. 

[Authorized("Admin,UserEditor")]
ActionResult EditUser(int? Id)
{
........
}  

Best Regards,
KIM
Petur Subev
Telerik team
 answered on 31 Oct 2014
1 answer
231 views
Hi,

I am using Kendo Tree View.
I construct a HierarchicalDataSource, but I get a 'stack overflow' error when I try to call SetDataSource to bind the data.
I get this error in IE 8.0.7601.17514CO 64bit, and no error in chrome.

here is my code:

public class TDNode
    {
        public string id { get; set; }
        public string text { get; set; }
        public string ctrlTypeCssClass { get; set; }
        public bool expanded { get; set; }
        public bool hasChildren { get; set; }
        public string parentid { get; set; }
        public List<TDNode> items = new List<TDNode>();
    }

 success: function (data) {
                var newDataSource = null;
                newDataSource = new kendo.data.HierarchicalDataSource({
                    data: data
                });

                $("#tvtemplate").data("kendoTreeView").setDataSource(newDataSource);
            }

Thanks.


Alex Gyoshev
Telerik team
 answered on 31 Oct 2014
3 answers
126 views
In our JS onClick event we have the following code:

        var grid = $("#MyGrid").data("kendoGrid");
        var row = grid.select();

When running on IE (test on versions 9, 10, 11) the row is null if the row isn't specifically selected before clicking on the button. Any work around for this?

thanks

Bill
Dimiter Madjarov
Telerik team
 answered on 31 Oct 2014
1 answer
186 views
I need to know how to properly build a gridtemplatecolumn in code behind.

@(Html.Kendo().Grid<DealViewModel>().Name("Grid").AutoBind(false).Scrollable(x => x.Height("auto")).Columns(columns =>
                                                                                                              columns.AutoGenerate(a =>
                                                                                                              {
                                                                                                                  a.Encoded = false;
                                                                                                              })).Columns((columns) => Utilities.SetColumnProperties(columns.Container.Columns, @ViewBag.CurrentStepId)).Sortable(x=>x.SortMode(GridSortMode.SingleColumn))

the second columns call the SetColumnProperties method where I query the database to get the columns properties that are set by the user as follows.

/////////////
/////////////
/////////////


public static void SetColumnProperties(IList<GridColumnBase<DealViewModel>> columns, Guid currentStepId)
{
var column = ContextHelper.Context.SalesStep.Find(currentStepId).Column.ToList();
var columnsToAdd = new List<GridColumnBase<DealViewModel>>();

columns.ForEach(x =>
{
var currentColumn = column.FirstOrDefault(y => y.ColumnName.Name.Equals(x.Member, StringComparison.InvariantCultureIgnoreCase));

x.Visible = currentColumn != null;
var gridBoundColumn = x as IGridBoundColumn;
if (gridBoundColumn == null || currentColumn == null)
{
return;
}
//TASKS ENABLED
if (x.Member.Equals("TaskTo"))
{
x.Visible = TaskingUtilities.TaskingEnabled;
}

if (new List<string>
{
"TaskTo",
"TakeOwnership",
"ReturnButton",
"RejectTask",
"CompleteTask",
"Approve",
"ApproveTo",
"Deny",
"DenyTo"
}.Contains(x.Member))
{
var claims = ClaimsPrincipal.Current.Claims;
var firstOrDefault = claims.FirstOrDefault(y => y.ValueType.Equals(currentStepId.ToString()));
if (firstOrDefault != null)
{
var enumString = firstOrDefault.Value;
SedonaSalesWorkflow.StepAccessLevel returnVal;
var stepAccessLevel = Enum.TryParse(enumString, true, out returnVal) ? returnVal : SedonaSalesWorkflow.StepAccessLevel.None;

x.Visible = stepAccessLevel == SedonaSalesWorkflow.StepAccessLevel.Full;
}
else
{
x.Visible = false;
}
}




if (currentColumn.Width != 0)
{

x.Width = currentColumn.Width.ToString(CultureInfo.InvariantCulture) + "px";
}
gridBoundColumn.Hidden = currentColumn.IsHidden;
gridBoundColumn.Title = currentColumn.Title;
gridBoundColumn.Format = currentColumn.Format;
gridBoundColumn.Filterable = currentColumn.Filterable;
gridBoundColumn.Sortable = currentColumn.Sortable;
gridBoundColumn.Groupable = currentColumn.Groupable;                
});
}//////////////////////////

/////////////

/////////////
Now how do I add a GridTemplateColumn correctly.  I can get it to show but I want to build a column dynamically from code behind.  There is basically one grid that users can add/remove fields to and create a new page and then set properties on that field which is why this is done this way.  I would like to basically concatenate columns of a certain type.

This currently does not work
columns.FirstOrDefault().Grid.Columns.Add(new GridTemplateColumn<DealViewModel>(columns.FirstOrDefault().Grid, model => model.Approve)
            {
                ClientTemplate = "#= Approve #"
            });

Thanks for the help.
































Petur Subev
Telerik team
 answered on 31 Oct 2014
1 answer
736 views
Hi, 

I'm using the numeric text box as follows: 

<div class="col-md-7 col-sm-6">
    @(Html.Kendo().NumericTextBoxFor(m => m.MaintenanceYearlyAmount).Decimals(1).Deferred(true))
    @Html.ValidationMessageFor(m => m.MaintenanceYearlyAmount)
</div>

The model property 'MaintenanceYearlyAmount' has the following attributes for validation: 
[Display(Name = "Annual Maintenance")]
[Required]
[Range(0,1000)]
[ToolTip("Dependant's Annual Maintenance")]
public decimal? MaintenanceYearlyAmount
{
    get
    {
        return ModelEntity.MaintenanceYearlyAmount;
    }
    set
    {
        ModelEntity.MaintenanceYearlyAmount = value;
    }
}

When testing this I get the following results: 
  • I enter 999.56 - It rounds up to 999.60 (Why is it showing the additional zero at the end when I've specified only 1 decimal?)
  • I enter 1111 and tab off the control - I get a valid validation message of 'Please enter a value less than or equal to 1000' AND it automatically changes the value to 1000 (is there a way to stop this from happening? The user should be warned, but it's there responsibility to change the value not to have it automatically changed. They might have entered 9845 accidentally adding the 5 at the end and instead of just deleting the 5 they have to type the number out again. 
  • I remove the Range validation and keep only the Required validation.  
    • I delete the current value for MaintenanceYearlyAmount and for Full Name (which is a normal Microsoft textbox and is required in the model) and click save. - Full name correctly shows its validation message, but the Kendo numeric textbox doesn't. This is where the problem is. I'm not sure why the client side validation doesn't fire correctly or show the validation message. If I add the Full name value back and click submit/save again, Full name passes, the form submits and server side validation fails sending the form back with the correct message under the MaintenanceYearlyAmount input. So bottom line is that the validation works server side, but not client side for the Required Validator. 
Georgi Krustev
Telerik team
 answered on 30 Oct 2014
1 answer
350 views
I have tried to follow the Kendo example (http://demos.telerik.com/aspnet-mvc/grid/filter-menu-customization) but I am clearly missing something...

The grid loads data just fine. The javascript function `costCenterNumberFilter(element);` is executed as I have placed an `alert("blah");` and that is displayed in the browser...

It will not render the AutoComplete for cost center number filter. Any help will be greatly appreciated.


Index.cshtml:

@model IEnumerable<LoanFee>
 
@{
    ViewBag.Title = "Fees";
}
 
@(Html.Kendo().Grid<LoanFee>(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Command(cmd => cmd.Select())
            .HtmlAttributes(new { style = "text-align: center;" })
            .Width(100);
        columns.Bound(p => p.AccountNumber)
            .Width(170);
        columns.Bound(p => p.CustomerName);
        columns.Bound(p => p.StatusId)
            .Template(@<text></text>)
            .HtmlAttributes(new { @class = "status-dropdown" })
            .ClientTemplate(Html.Kendo().DropDownList()
                .Name("ddlStatus_#=LoanFeeId#")
                .DataTextField("Name")
                .DataValueField("Value")
                .BindTo(Status.Items())
                .Value("#=StatusId#")
                .ToClientTemplate()
                .ToHtmlString())
            .Title("Status")
            .Width(100);
        columns.Bound(p => p.Approvals)
            .HtmlAttributes(new { style = "text-align: center;" })
            .Width(100);
        columns.Bound(p => p.Amount)
            .Format(Formats.CURRENCY)
            .HtmlAttributes(new { style = "text-align: right;" })
            .Width(120);
        columns.Bound(p => p.Allocation.PrimaryOfficerName)
            .Template(@<text></text>)
                .ClientTemplate("#=Allocation.PrimaryOfficerNumberDashName#")
            .Width(220);
        columns.Bound(p => p.CostCenterNumber)
            .Title("Cost Center")
            .HtmlAttributes(new { style = "text-align: center;" })
            .Filterable(filterable =>
            {
                filterable.Extra(false);
                filterable.Operators(o => o.ForString(fs =>
                {
                    fs.Clear();
                    fs.Equals("Equals");
                }));
                filterable.UI("costCenterNumberFilter");
            })
            .Width(100);
        columns.Bound(p => p.DateEntered)
            .Format(Formats.DATE)
            .HtmlAttributes(new { style = "text-align: center;" })
            .Width(100);
 
    })
    .Events(e => e.DataBound("initStatusDropdown"))
    .Pageable()
    .Filterable()
    .DataSource(ds => ds
        .Ajax()
        .PageSize(15)
        .Sort(sort => sort.Add(p => p.AccountNumber))
        .Model(m =>
        {
            m.Id(p => p.LoanFeeId);
        })
        .Read(read => read.Action("Index_Read", "WorkQueue"))
    )
)
 
<script type="text/javascript">
 
    function initStatusDropdown(e) {
 
        $(".status-dropdown").each(function () {
 
            eval($(this).children("script")
                .last()
                .html());
        })
    }
 
    function costCenterNumberFilter(element) {
 
        element.kendoAutoComplete({
            datasource: ["3200", "4200", "1000"]
        });
    }
 
</script>


WorkQueueController.cs:

using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
 
namespace CommercialIncentive.Web.Areas.Fees.Controllers
{
    public class WorkQueueController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }
 
        public ActionResult Index_Read([DataSourceRequest] DataSourceRequest request)
        {
            var data = IocContainer.Get<ILoanFeeService>()
                    .ListAsQuery()    // Returns IQuerable<LoanFee>
                    .ToDataSourceResult(request);
 
            return Json(data);
        }
    }
}


John
Top achievements
Rank 2
 answered on 30 Oct 2014
1 answer
151 views
Is there a spell checker for MVC?
If not will there be one soon?
Thanks
Robert
Kiril Nikolov
Telerik team
 answered on 30 Oct 2014
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
ComboBox
Upload
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
Accessibility
ListView (Mobile)
Pager
ColorPicker
DateRangePicker
Wizard
Security
Styling
Chat
DateInput
MediaPlayer
TileLayout
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
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?