Telerik Forums
UI for ASP.NET MVC Forum
0 answers
195 views
Hi,

Is there any sample showcasing how can we bind a Kendo Grid to WebApi using actions that do not follow the Telerik proposed signatures (DataSourceRequest) using the MVC Extensions?

I would like to make my API available for others to use and the DataSourceRequest in the input does not fit well in that requirement. I want to bind a grid to a controller that returns and receives my pure objects. For sorting and paging I would need to add extra arguments but I would prefer not to bind to a proprietary solution.

Thanks,
Pedro
Pedro
Top achievements
Rank 1
 asked on 04 Jul 2012
4 answers
166 views
The grid is bound like this:
 
@(Html.Kendo().Grid(Model).Name("organizationsGrid"))

The action is like this:

var model = new List<OrganizationSummaryModel> {
                new OrganizationSummaryModel { Code = "Xyz", Description = "Xyz Organization" },
                new OrganizationSummaryModel { Code = "Abc", Description = "Abc Organization" }
            };


return View(model); Throws this exception: System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) +64 System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item) +10635094 Kendo.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) +746 Kendo.Mvc.UI.ViewComponentBase.ToHtmlString() +115 Kendo.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString() +62 System.Web.HttpUtility.HtmlEncode(Object value) +38 System.Web.WebPages.WebPageBase.Write(Object value) +68 ASP._Page_Views_account_SelectOrganization_cshtml.Execute() Using: Visual Studio 2010 with MVC 4 RC.
Pedro
Top achievements
Rank 1
 answered on 04 Jul 2012
2 answers
464 views
I noticed that while Telerik ASP.NET MVC ships with the unminified JS files, Kendo UI Complete for ASP.NET MVC does not (at least not for Beta 2). Is there a link to the unminified scripts such as http://cdn.kendostatic.com/2012.2.621/js/kendo.all.js
Matt
Top achievements
Rank 1
 answered on 03 Jul 2012
2 answers
334 views
I can't get MVC 3 model validation to work using the Kendo validator. I get a "syntax error, unrecognized expression" thrown from kendo.aspnet.mvc.js.

I can get it to work if I change line 432, which is the 'locate' function of the mvcLocator message locator. I added single quotes around the fieldname.

return element.find(".field-validation-valid[data-valmsg-for='" + fieldName + "'], .field-validation-error[data-valmsg-for='" + fieldName + "']");<br> 

Is this a bug?
Matt
Top achievements
Rank 1
 answered on 03 Jul 2012
1 answer
221 views
Hi,

I get the error "Uncaught ReferenceError: Customer is not defined" when i try and create a new row on the grid. It will display the data correctly.

My grid is defined like this ...

@(Html.Kendo().Grid(Model)
    .Name("OrderGrid")
    .Columns(columns =>
    {
        columns.Bound(o => o.OrderId).Title("Order Id");
        columns.Bound(o => o.Customer.CustomerName).Title("Customer Name");
        columns.Bound(o => o.AccountManager).Title("AccountManager");
        columns.Command(command => { command.Destroy(); command.Edit(); });
    })
    .Pageable()
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .ToolBar(commands => commands.Create().Text("New Order"))
    .Filterable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(o => o.OrderId))
        .Events(events => events.Error("error"))
        .Create(create => create.Action("Orders_Create", "Order"))
        .Read(read => read.Action("Orders_Read", "Order"))
        .Update(update => update.Action("Orders_Update", "Order"))
        .Destroy(destroy => destroy.Action("Orders_Destroy", "Order"))
    )
)

And my models are like this...

public class Order
    {
        public int OrderId { get; set; }
        public int CustomerId { get; set; }
        public string AccountManager { get; set; }
        public Customer Customer { get; set; }
    }
 
public class Customer
    {
        public int CustomerId { get; set; }
        [Required]
        public string CustomerName { get; set; }
        [Required]
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string Address3 { get; set; }
        public string City { get; set; }
        public string County { get; set; }
        [Required]
        public string Postcode { get; set; }
 
        private ICollection<Order> Orders { get; set; }
    }


I guess this is because CustomerName is stored in a different table, but I can't figure out why. Any help would be great, I am so lost on this one.

Thanks,
Chris
Chris
Top achievements
Rank 1
 answered on 03 Jul 2012
3 answers
627 views
Scenario:

I have objects in the database I want to bind to a Grid. But those objects need to be converted into Models in order to avoid circular references in serialization, or to be able to have one of your Model properties equal a string representation of a child object.

A typical method of accomplishing this transformation using the Entity Framework is to materialize the query to a list, and then call materializedList.Select(c => c.ToModel()).

The problem is, it is not readily apparent how this is possible with the DataSourceRequest and DataSourceResult, because DataSourceResult.Data is not generic. And I know there is an example controller called CustomServerBinding that demonstrates this scenario, but it looks ridiculously complicated to implement for most scenarios.

I see two possibilities to handle this scenario:
  • Create an extension to IQueryable called ApplyGridParameters(DataSourceRequest) that would accomplish everything in ToDataSourceResult() EXCEPT for returning the DataSourceResult. Then, add an extension method for IEnumerable called ToDataSourceResult() that does not take a DataSourceRequest object. That version of the method would already assume the filters have been applied, and just load up the DataSourceResult properly.
This would allow me to write code like:
var transformedList = dbResults.ApplyGridParameters(kendoRequest).ToList().Select(c => c.ToModel());
return Json(transformedList.ToDataSourceResult());

  • Create an overload to IQueryable.ToDataSourceResult(DataSourceRequest) that allows me to pass in a Func to apply to the data after the query is materialized, but before it is set to the DataSourceResult.Data property. This option would be the most flexible, because you could literally do anything with it.
This would allow me to write code like:
return Json(dbResults.ToDataSourceResult(request, c => c.ToModel());

or even something like this:
var results = dbResults.ToDataSourceResult(request, c => { DoSomething(c); DoSomethingElse(c); });
return Json(results);

Obviously, this method looks a lot cleaner.

For now, I'm left with getting everything from the database, and filtering it after the fact. One of these options would allow me to pass the query back with minimal effort, and transform only the data I'm actually going to use.

Thanks!
Atanas Korchev
Telerik team
 answered on 02 Jul 2012
3 answers
155 views
Given the following model:

    public class PropertyUnitModel
    {
        public Guid Id { get; set; }
 
        public Guid PropertyId { get; set; }
 
        public Guid FloorPlanId { get; set; }
 
        [Display(Name = "Floor Plan", Description = "Floor Plan", GroupName = "Floor Plan")]
        public string FloorPlanName { get; set; }
 
        public string UnitNumber { get; set; }
 
        [Display(Name = "SqFt")]
        public int SquareFootage { get; set; }
 
        public string Notes { get; set; }
}

And the following Grid definition:
@(Html.Kendo().Grid<PropertyUnitModel>()
    .Name("propertyUnitsGrid")
    .Columns(columns =>
        {
            columns.Bound(p => p.UnitNumber).Groupable(false).Width(100);
            columns.Bound(p => p.SquareFootage).Groupable(false).Width(70);
            columns.Bound(p => p.Notes).Groupable(false);
        })
    .Sortable()
    .Pageable(pager => pager.Refresh(true).PreviousNext(false).PageSizes(false).Input(false).Numeric(false))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Group(groups => groups.Add(p => p.FloorPlanName))
        .Model(model => model.Id(p => p.Id))
        .Read(read => read.Action("GetAllByProperty", "PropertyUnits", new { PropertyId = Model.Id }))
    ))

I am getting the following Grid rendering:

I do not believe this is correct. The groups should read: Floor Plan: Plan 1 [1.0BR + 1.0BA] and Floor Plan: Plan 2 [2.0BR + 1.0BA].

I don't want the actual name of the field displayed, that's why I put in the [Display] attributes, which the column rendering honors. But since the DisplayAtribute has a GroupName property, the Grid should be honoring that first, then the Name if GroupName is not present, then if neither are present, the property name.

Thanks!
Atanas Korchev
Telerik team
 answered on 02 Jul 2012
2 answers
149 views
Hello,

I would like to request that you guys add an event after a Grid Save ajax call completes successfully. I need to be able to synchronize the contents of two grids (when one updates, the other fetches new data) and right now there is no event I can call that isn't super chatty (meaning it also fires at times other than when the data source changes).

Preferably like a SaveCompleted event or something like that.

Thanks!
Robert
Top achievements
Rank 1
 answered on 02 Jul 2012
1 answer
569 views
Hi,

I'm trying to use the ToDataSourceResult inside an MVC 4 Web API controller like so (wrong, I know, please help)

public DataSourceResult Get([DataSourceRequestDataSourceRequest request)
{
	DataSourceResult dataSourceResult;
 
	using (MobookaEntities entities = new MobookaEntities(false))
	{
		IQueryable<Campaign> campaigns = entities.Campaigns.Include("Offer")
								   .Include("Offer.Advertiser")
								   .Include("Offer.Advertiser.Company")
								   .Include("Publisher")
								   .Include("Publisher.Company")
								   .Include("Publisher.Employee")
								   .Include("Publisher.Employee.Profile")
								   .Include("Publisher.Profile")
								   .Include("Status");
 
		dataSourceResult = campaigns.ToDataSourceResult(request);
	}
return dataSourceResult; }

But I'm getting the following error:

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

I kind of understand why I'm getting this and if I copied the DataSourceResult object into a different object and returned that then it would work, however, I would like to know what do I need to do to have the LINQ executed and returned in my controller. Thank you!
Atanas Korchev
Telerik team
 answered on 02 Jul 2012
3 answers
436 views
I want to compare a column (QtyReceived) to another column (QtyShipped) and change the background color of the QtyReceived column if it is less than QtyShipped. I need to be able to do the compare when the grid is first fired then after the user edits the QtyReceived column.
Pechka
Top achievements
Rank 1
 answered on 02 Jul 2012
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
Dialog
MultiColumnComboBox
DropDownTree
Checkbox
Slider
Switch
Notification
Accessibility
ListView (Mobile)
Pager
Security
ColorPicker
DateRangePicker
Wizard
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
SmartPasteButton
PromptBox
SegmentedControl
+? more
Top users last month
Miljana
Top achievements
Rank 2
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Bronze
Cynthia
Top achievements
Rank 1
John
Top achievements
Rank 1
Iron
Mozart
Top achievements
Rank 1
Iron
Veteran
Want to show your ninja superpower to fellow developers?
Top users last month
Miljana
Top achievements
Rank 2
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Bronze
Cynthia
Top achievements
Rank 1
John
Top achievements
Rank 1
Iron
Mozart
Top achievements
Rank 1
Iron
Veteran
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?