Telerik Forums
UI for ASP.NET MVC Forum
0 answers
133 views
Below is my grid.  I set my filter and ordering, click the Details, click back to the Index view and the filter and ordering are lost.  

<h2>Load Summary</h2>
@(Html.Kendo().Grid<MyProject.Models.Invoice>()
    .Name("grid")
    .HtmlAttributes(new { style = "width: 100%" } )
    .Columns(columns => 
        {
            columns.Template(@<text>@Html.ActionLink("Details", "Invoice", "Details", new { id = @item.InvoiceID })</text>)
                .ClientTemplate("<a href='/Invoice/Details/#= InvoiceID#'>Details</a>").Width("5%");
            columns.Bound(p => p.InvoiceNumber).Width("5%").Title("Load No.");
            columns.Bound(p => p.BookDate).Format("{0:d}").Width("5%");
        })
    .DataSource(datasource => datasource
        .Ajax()
        .Read(read => read.Action("GetLoads", "Invoice"))
        .Model(m => m.Id(model => model.InvoiceID))
        )
    .Pageable()
    .Sortable()
    .Filterable()
    .Selectable(selectable => selectable
        .Mode(GridSelectionMode.Single))
)

Here are my controller actions:
        public ActionResult Index()
        {
            IEnumerable<Invoice> invoices = _db.Invoices.Where(p => p.SalesmanID == _salesmanId);
            return View(invoices.ToList());
        }


        //
        // GET: /Invoice/Details/5


        public ActionResult Details(int id = 0)
        {
            Invoice invoice = _db.Invoices.Find(id);
            if (invoice == null)
            {
                return HttpNotFound();
            }
            _routeValues = this.GridRouteValues();
            InvoiceViewModel invoiceViewModel = Mapper.Map<Invoice, InvoiceViewModel>(invoice);
            return View(invoiceViewModel);
        }


        [HttpPost]
        public ActionResult Details(string btnSubmit)
        {
            
            return RedirectToAction("Index", _routeValues);
        }


How can I code this to keep my Filtering and Ordering on my grid?
Thanks

Paul Sieloff
Top achievements
Rank 1
 asked on 20 Nov 2012
1 answer
114 views
Hi,

I have a grid that has 2 columns, something like the following:

Country India USA

GDP ($ trn) 1.85 15.09

Inflation (%) 7.9 2.0

Countries are selectable from dropdown lists, whereas the statistics pertaining to them are shown in read-only textboxes.

Now on top of the grid, I have a button titled 'Add', on clicking which a new templated column needs to get added to the grid. In the new column, I should be able to select a country from the dropdown list and then enter values for its GDP and inflation rate (textboxes for GDP and inflation in the new column are editable, unlike the ones for existing columns, which are read-only.)

Would the gridbuilder class be useful here? I was just taking a casual look at its documentation, don't know if it could help me.

Please advise on how this could be done.

Petur Subev
Telerik team
 answered on 20 Nov 2012
2 answers
193 views
In my project this code
@(Html.Kendo().DropDownListFor(x => x.Event.DisconnectionId)
                               .DataValueField("Id")
                               .DataTextField("Name")
                                          .DataSource(source =>
                                          {
                                              source.Read(read =>
                                              {
                                                  read.Action("_Disconnections", "Event");
                                              })
                                              .ServerFiltering(true);
                                          })
                             )


generates following html

<input id="Event_DisconnectionId" name="Event.DisconnectionId" type="text" value="0" /><script>
   jQuery(function(){jQuery("#Event_DisconnectionId").kendoDropDownList({dataTextField:"Name",dataValueField:"Id"});});

Could not read  "disconnections" data because datasource property (dataSource:{transport:{read:{url:"/Event/_Disconnections" ... etc. ) is not generated. Why? Please help.

Szymon
Top achievements
Rank 1
 answered on 20 Nov 2012
1 answer
146 views
Hi Guys,

I've been looking high and low for example on showing how to implement drag and drop with the Kendo grid in MVC3 and Razor. Could anyone help me out here?

William
Samuel
Top achievements
Rank 1
 answered on 19 Nov 2012
1 answer
323 views
Hello
I have a grid razor as follows. How can I add auto complete to grid column and not to single text box.
@(Html.Kendo().Grid(Model)   
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(model => model.MEMBER_ID);
        columns.Bound(model => model.R_MONTH);
        columns.Bound(model => model.PRINT_YN);
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
    })
    .ToolBar(toolbar =>
    {
        toolbar.Create();
    })
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Scrollable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Events(events => events.Error("error_handler"))
        .Model(p => p.Id(model => model.SR_NO))
        .Create(update => update.Action("Editing_Create", "Repost"))
        .Read(read => read.Action("Editing_Read", "Repost"))
        .Update(update => update.Action("Editing_Update", "Repost"))
        .Destroy(update => update.Action("Editing_Destroy", "Repost"))
    )
)
AspenSquare
Top achievements
Rank 1
 answered on 19 Nov 2012
1 answer
409 views
I'm trying to create a custom Delete button for my grid that fires off a custom function. The only problem I'm having is actually deleting the row from the grid. How could I accomplish this?
AspenSquare
Top achievements
Rank 1
 answered on 19 Nov 2012
3 answers
590 views
I'm using the popup editing mode with a custom MVC template for editing, having just created an EditorTemplate with the name of my model. Within this template I have two DropDownLists, both bound using a similar method; each have a custom template and these are specified by way of UIHint metadata on my model properties. All this works fine for edits; the DDL values are posted back correctly, and I even see the background grid change dynamically as I change the values before doing the Update.

However, inserts don't work. The same edit template appears and the text fields update the background grid dynamically, but the DDLs don't. When posted back, the ID values don't have the ID values from the DDLs, but the text values. This of course causes validation to fail.

Edit: Sample project attached. Ignore the fact that the two DDL values don't show in the grid initially; they do in the full solution so I've just missed something here. But if you edit an item and select values from the two DDLs, that's fine. Not so with the Create.

Side question: when using the same template for Edit/Create can we change the title of the popup window?


Edit 2: Ok, more investigation this morning, after hacking a workaround. It looks like the request form variables come back different between Edit and Create, even though they use the same editor. I'm currently seeing the following in Request.Form:

DefaultWorkPoolId.Id
DefaultWorkPoolId.Name
DefaultWorkPoolId[Id]
DefaultWorkPoolId[Name]

Clearly the model binding can't bind these to the property, which is DefaultWorkPoolId, but the question is why the Create behaviour is different. It would be good to get an answer on this so I can remove the hacked code; this is only the first screenof many and I don't want to have to repeat this everywhere.
jonathan
Top achievements
Rank 1
 answered on 19 Nov 2012
0 answers
195 views
Ok so my problem is maybe simple but I can't handle it i tried all known for me methods ...

Error looks like this: 

The model item passed into the dictionary is of type 'System.Data.Objects.ObjectSet`1[Repository.Database.Book]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Biblioteka.ViewModels.BookViewModel]'.


My Index:

@model IEnumerable<Biblioteka.ViewModels.BookViewModel>
 
@{
    ViewBag.Title = "Index";
}
 
<h2>Index</h2>
 
 
 
@(Html.Kendo().Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.BookGenreId).Groupable(false);
        columns.Bound(p => p.Title);
        columns.Bound(p => p.Author);
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()   
    .DataSource(dataSource => dataSource       
        .Ajax()
        .ServerOperation(false)       
     )
)

My BookController:

namespace Biblioteka.Controllers
{
    public class BooksController : Controller
    {
        //
        // GET: /Books/
        public ActionResult Index()
        {
            return View(GetData());
        }
 
        private IEnumerable<dynamic> GetData()
        {
            LibraryEntities ctx;
            ctx = new LibraryEntities();
            return ctx.Book;
        }
 
        private JsonResult GetView()
        {
            return Json(GetData());
        }
    }
}

And for help my class:

namespace Biblioteka.ViewModels
{
    public class BookViewModel
    {
 
        public int BookId { get; set; }
        public string Author { get; set; }
        public string Title { get; set; }
        public Nullable<System.DateTime> ReleaseDate { get; set; }
        public string ISBN { get; set; }
        public int BookGenreId { get; set; }
        public int Count { get; set; }
        public System.DateTime AddDate { get; set; }
        public Nullable<System.DateTime> ModifiedDate { get; set; }
     
 
        public BookViewModel()
        {
        }
 
        public BookViewModel(Book book)
        {
            this.BookId = book.BookId;
            this.Author = book.Author;
            this.Title = book.Title;
            this.ReleaseDate = book.ReleaseDate;
            this.ISBN = book.ISBN;
            this.BookGenreId = book.BookGenreId;
            this.Count = book.Count;
            this.AddDate = book.AddDate;
            this.ModifiedDate = book.ModifiedDate;
        }
 
        public void Update(Book book)
        {
            book.BookId = this.BookId;
            book.Author = this.Author;
            book.Title = this.Title;
            book.ReleaseDate = this.ReleaseDate;
            book.ISBN = this.ISBN;
            book.BookGenreId = this.BookGenreId;
            book.Count = this.Count;
            book.AddDate = this.AddDate;
            book.ModifiedDate = this.ModifiedDate;
        }
    }
}
Karol
Top achievements
Rank 1
 asked on 19 Nov 2012
0 answers
253 views
have such grid defined

@(Html.Kendo().Grid<FieldViewModel>(Model.Fields)
    .HtmlAttributes(new { @class = "fullScreen" })
    .Name("formFields")
    .ClientDetailTemplateId("formFieldsTemplate")
    .Columns(columns =>
        {
            columns.Bound(e => e.Key);
            columns.Bound(e => e.DisplayName);
            columns.Bound(e => e.FieldTypeName);
            columns.Bound(e => e.Order);
            columns.Bound(e => e.IsMandatory);
            columns.Bound(e => e.Type);
        })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Selectable()
    .Resizable(resize => resize.Columns(true))
    .Groupable()
    .Filterable()
      .DataSource(dataSource => dataSource.Ajax().ServerOperation(false).Model(model => model.Id(e => e.Key))))
and details template

<script id="formFieldsTemplate" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<FieldViewModel>()
        .Name("FormField_#=Key#")
        .ClientDetailTemplateId("formFieldsTemplate")
        .Columns(columns =>
            {
                columns.Bound(e => e.Key);
                columns.Bound(e => e.DisplayName);
                columns.Bound(e => e.FieldTypeName);
                columns.Bound(e => e.Order);
                columns.Bound(e => e.IsMandatory);
                columns.Bound(e => e.Type);
            })
        .DataSource(dataSource => dataSource.Ajax().Read(read => read.Action("LoadFieldDetails", "Forms", new { formPath = Model.Schema, rootElementName = Model.Root ,fieldKey = "#=Key#" })))
        .Pageable()
        .Sortable()
        .Selectable()
        .ToClientTemplate())
</script>

As you can see I have Type property, so what I want to do is not to show any details view and no arrow on the entire row when Type property is set to the specific value. How can I achieve it?

Jevgenij
Top achievements
Rank 1
 asked on 19 Nov 2012
1 answer
170 views
I have 3 Kendo MVC AutoCompletes on a page, and they occasionally just decide not to work. I can't figure it out.

First of all, if I add a Change event, like so:

@(Html.Kendo().AutoCompleteFor(m => m.NewIssue.Responsible)
      .MinLength(3)
      .HtmlAttributes(new { @class="autocomplete" })
      .Events(e => e.Change("removeTitle"))
      .DataSource(ds => ds.Read(r => r.Action("GetUserNames", "Ajax"))
                          .ServerFiltering(true)))

It no longer calls my Ajax function to return user names. And of course, it doesn't drop down with values.

If I take out the Change event, sometimes it works and sometimes it doesn't. Sometimes it calls my Ajax function, gets a JSON list of users, but then doesn't dropdown with any values.

Here's another issue.
@(Html.Kendo().AutoCompleteFor(m => m.NewIssue.SiteNumber)
      .MinLength(3)
      .HtmlAttributes(new { @data_url = Url.Action("PopulateSite"), @class="autocomplete" })
      .Events(e => e.Select("selectSite"))
      .DataSource(ds => ds.Read(r => r.Action("GetSites", "Ajax"))
                          .ServerFiltering(true)))
This one calls it's Select event correctly when I select an item, but it also calls it's select event when I post the form using a regular Input Submit button. This one just blows my mind. I don't know how to fix this.

My project has 3 or 4 Kendo controls in it, and out of all of them, AutoComplete seems to be the most half-baked. It just doesn't seem reliable. I'm not doing anything crazy with them. I have 3 AutoCompletes in a form, one of them has a Select event, and I'm trying to add change events to the rest. I wonder if I should be using javascript to create these instead of the MVC wrapper, maybe that's causing issues? I really don't know.

Anyway, I'm not sure anyone can help me with the limited information I've provided, but I wanted to put it out here anyway. Thanks.
Georgi Krustev
Telerik team
 answered on 19 Nov 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
LLM Kit
+? more
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?