Telerik Forums
UI for ASP.NET MVC Forum
0 answers
130 views
While working through a process of batch editing a database tables that
had a timestamp field in each row for concurrency checking. It was not
immediately apparent the the return value for the update could be the
same as that for the create procedure.

Could you update your
documentation to explain that during an update you can return the
results of the update process to the grid.
so using generics the insert process can be:-

public
static DataSourceResult AddChanges<TEntity>([DataSourceRequest]
DataSourceRequest request, System.Data.Entity.DbContext context,
System.Web.Mvc.ModelStateDictionary modelState,
System.Collections.Generic.IEnumerable<TEntity> dbes)
where TEntity : class
{
   var results = new System.Collections.Generic.List<TEntity>();
   if (dbes != null && modelState.IsValid)
   {
      foreach (var dbe in dbes)
      {
         if (AddChanges<TEntity>(context, modelState, dbe))
            results.Add(dbe);
      }
   }
   return results.ToDataSourceResult(request, modelState);
}

and the update process can also be:-

public
static DataSourceResult SaveChanges<TEntity>([DataSourceRequest]
DataSourceRequest request, System.Data.Entity.DbContext context,
System.Web.Mvc.ModelStateDictionary modelState,
System.Collections.Generic.IEnumerable<TEntity> detached)
   where TEntity : class
{
   var results = new System.Collections.Generic.List<TEntity>();
   if (modelState.IsValid)
   {
      foreach (var dbe in detached)
      {
         if (SaveChanges<TEntity>(context, modelState, dbe))
            results.Add(dbe);
      }
   }
   return results.ToDataSourceResult(request, modelState);
}


NOTE the return of the results from the Save process

so in a controller the create and edit ActionResults would like :-
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult ProductPricingClientCreate([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductPricing> prices)
{
   return Json(PS.Common.DataAccess.AddChanges<ProductPricing>(request, db, ModelState, prices));
}

[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult ProductPricingGridUpdate([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductPricing> prices)
{
   return Json(PS.Common.DataAccess.SaveChanges<ProductPricing>(request, db, ModelState, prices));
}


Timothy
Top achievements
Rank 1
 asked on 24 Apr 2013
1 answer
299 views
Hi there,

I am continuing to eval the kendo grid for purchase and seeing if I can get it working in my application which is using MVC 4 and kendo 2013.1.319. 

While swapping in the dropdown I am running into an error for only certain records where the Select Event function on the dropdown is not recognized; even though it is present in the javascript. Its weird because it works for most records that visit the details page and once in awhile it breaks and I can't figure out why. Any ideas?

For example:

I am binding this list with a selectlist in the controller and the values are properly set. there is a full list and the Id is there in the list.

//select list on the viewmodel
pvModel.CostCenterList = new SelectList(_setupBiz.GetNonOverheadCostCenters(), "Key", "Value",pvModel.CostCenterId);

I have this DDL on the .cshtml page

                    @(Html.Kendo().DropDownList()
                        .Name("CostCenter")
                        .OptionLabel("Pick a costcenter...")
                        .BindTo(Model.CostCenterList)
                        .Events(e=>e.Select("CostCenterSelect"))
                        )

and this script in my <scripts> section

    function CostCenterSelect(e) {       
        var costCenter = this.dataItem(e.item.index());
        if (costCenter.Value > 0) {
//stuff happens
        }
        else {
//hide a bunch of buttons        }
    };







Tim
Top achievements
Rank 1
 answered on 24 Apr 2013
1 answer
124 views
Hi,

How to check kendo datasource is null before bind to any control
Vladimir Iliev
Telerik team
 answered on 24 Apr 2013
1 answer
85 views
Hello,

Spent hours trying to get this simple update sample to work.  Firefox shows that my model is being sent to my controller on an update but my controller receives a null model.  I must be missing something basic.  Thank you in advance.   VS2012.

Firefox debug info:

Parametersapplication/x-www-form-urlencoded

models
[{"OnTimeID":123,"Description":"Altamed staging issue","Status":"closed"}]

View:

<!doctype html>
<html>
@{
    ViewBag.Title = "OnTime Sample";
}
<head>
    <title>Kendo UI Web</title>
    <link href="~/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="~/styles/kendo.default.min.css" rel="stylesheet" />
    <script src="~/js/jquery.min.js"></script>
    <script src="~/js/kendo.web.min.js"></script>
</head>
<body>
  
    <div class="form">
        <div class="selector">
            Edit Product:
            <input type="text" id="onTimeIDs" />
        </div>
        <div id="container" class="container">
            <ul>
                <li>
                    <label>
                        OnTime ID</label>
                    <span data-bind="text:OnTimeID"></span></li>
                <li>
                    <label>
                        Description</label>
                    <input type="text" class="k-textbox" data-bind="value: Description" /></li>
                <li>
                    <label>
                        Status</label>
                    <input type="text" class="k-textbox" data-bind="value: Status" /></li>
            </ul>
            <button id="save">
                Save</button>
        </div>
    </div>
    <script>
  
  
    var crudServiceBaseUrl = "/Services",
        dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: crudServiceBaseUrl + "/OnTimeIDs_Get",
                    dataType: "json"
                },
                update: {
                    url: crudServiceBaseUrl + "/OnTimeIDs_Update",
                    type: "POST",
                    dataType: "json"
                },
                  
                parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return {                         
                            models: kendo.stringify(options.models)
                        };
                    }
                }
                 
            },
  
  
            batch: true,
            schema: {
                model: {
                    id: "OnTimeID",
                    fields: {
                        OnTimeID: {
                            editable: false,
                            nullable: true
                        },
                        Description: { type: "string" },
                        Status: { type: "string" }
                    }
                }
            }
        }
    );
  
  
        $("#onTimeIDs").kendoDropDownList({
            dataSource: dataSource,
            dataTextField: "Description",
            dataValueField: "OnTimeID",
            change: function () {
                var model = dataSource.get(this.value());
                kendo.bind($("#container"), model);
            }
        }).data("kendoDropDownList")
            .one("dataBound", function () {
                kendo.bind($("#container"), dataSource.view()[0]);
            });
  
        $("button").click(function () {
            dataSource.sync();
        });
    </script>
</body>
</html>


Controller:

Why does OnTimeIDs_Update() receive a null parameter?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCTimeCard.Models;
  
namespace MVCTimeCard.Controllers
{
    public class ServicesController : Controller
    {
  
        public ActionResult OnTimeIDs_Get()
        {
            List<OnTimeItem> otiList = new List<OnTimeItem>() {
                new OnTimeItem {OnTimeID = 123, Description = "Altamed staging issue", Status = "Open"},
                new OnTimeItem {OnTimeID = 456, Description = "HILL staging issue", Status = "Open"},
                new OnTimeItem {OnTimeID = 789, Description = "PPMSI staging issue", Status = "Open"}
            };
  
            return Json(otiList, JsonRequestBehavior.AllowGet);         
        }
  
        [HttpPost]
        public ActionResult OnTimeIDs_Update( IEnumerable< OnTimeItem>  otis)
        {
  
            return Json(otis, JsonRequestBehavior.AllowGet);    
        }
    }
}
Derek
Top achievements
Rank 1
 answered on 24 Apr 2013
1 answer
166 views
Hi,

I'm currently working on a kendo grid using MVC helpers, and I've been having a bit of a hard time to find a way to set a individual filter as extra = true.

Here is the code that I'm using to disable the extra filters for the grid:

.Filterable(fltr => fltr.Extra(false).Messages(m => m.IsTrue(" Yes").IsFalse(" No")).Operators(op => op.ForString(str => str.Clear()))))

This is at the end of the grid and works just fine.
However I want to have a single column as extra (the date column to be precise), however the column Filterable only takes a bool (whether it's filterable or not at all).

I would be very grateful if you could point me in the right direction regarding this.

Thanks,

W. Akram
Daniel
Telerik team
 answered on 23 Apr 2013
6 answers
1.7K+ views
I'm using the kendo grid to display users. I want to have a button for each user that can be clicked on to link to a page to edit user details.
I have the following code to display the required fields and use the ClientTemplate method to display the button that links to the edit user page.
@(Html.Kendo().Grid<Extranet.Web.Models.UserListViewModel.UserList>(Model.Users)
.Name("Grid")
.Columns(columns =>
             {
                 columns.Bound(u => u.UserView.UserName);
                 columns.Bound(u => u.UserView.Name);
                 columns.Bound(u => u.UserView.UserRole);
                 columns.Bound(u => u.UserView.CreatedOn);
                 columns.Template(@<button class="k-button" value="@Url.Action("EditUser")/@item.UserView.ID">Edit</button>)
                        .ClientTemplate("<button value='" + Url.Action("EditUser", "Admin") + "/#=ID#>Edit</button>");
             })
 .Pageable()
 .Filterable()
 .Sortable()
 .Selectable()
 .DataSource(dataSource => dataSource
    .Ajax()
    .ServerOperation(false)
    .Read(read => read.Action("AllUsers", "Admin"))
    )
)
When the page is rendered in a browser it shows all the columns as expected and the button that I can use to link to the appropriate page. However the grid goes in to limp mode and will not change page, sort or filter.

If I take the following line of code out then the grid works fine.
columns.Template(@<button class="k-button" value="@Url.Action("EditUser")/@item.UserView.ID">Edit</button>)
       .ClientTemplate("<button value='" + Url.Action("EditUser", "Admin") + "/#=ID#>Edit</button>");
Am I doing something wrong or is there an alternative way to achieve what I am trying to do?
Ryan
Top achievements
Rank 1
 answered on 23 Apr 2013
4 answers
304 views
I've assigned an ID attribute to each of my tree nodes to keep a hold of information I need on the controller so that I can save a modified Hierarchy.

However, when I drop a node, the Id attribute is removed.  I'm not sure if this is a bug, if I'm doing something wrong, or this is working as intended by the developers.

I've attached a screenshot of my alert window (code below), and two shots of the Html generated from Firebug.  One is before the Drop and one is from after.

@(Html.Kendo().TreeView()
    .Name("CompanyHierarchy")
    .Events(events => events
        .DragEnd("HierarchyDragEnd")
    )
    .BindTo(Model.Hierarchy as System.Collections.IEnumerable, mappings =>
    {
        mappings.For<BlueGrace.BlueShip.MVC.Models.EnterpriseChildModel>(binding => binding
            .Children(c => c.Children)
            .ItemDataBound((item, c) =>
            {
                item.Text = c.Name;
                item.HtmlAttributes.Add("Id", c.EnterpriseID.ToString() + "|" + c.EnterpriseID.ToString());
            })
        );
    })
    .DragAndDrop(true)
)

<script>
        function HierarchyDragEnd(e) {
            setTimeout(function () {
                var originNode = e.sourceNode.id;
                var destinationNode = e.destinationNode.id;
                var loc = e.dropPosition;
                alert("Origin ID: " + originNode + "\nDestination ID: " + destinationNode + "\nDrop Position: " + loc);
            }, 100);
        }
</script>
Alex Gyoshev
Telerik team
 answered on 23 Apr 2013
3 answers
609 views
When I click the edit button in the grid view the row extends vigorously, which overlaps my other control horizontally. I want to fix the size of the grid row same as the non editable mode when i will be in editable mode.
Dimo
Telerik team
 answered on 23 Apr 2013
1 answer
84 views
where to add default massage, if data not available for charts, for blank chart, like "No data points are available" and
 if data is not available, right & left axis are coming close, i want to show that massage in between this two axis.
Iliana Dyankova
Telerik team
 answered on 22 Apr 2013
18 answers
2.6K+ views
I can get a Grid to be 100% high by setting parent containers to be 100% as well.

But inside an MVC splitter pane this does not work and the grid seems to expand to 100% of the browser rather than the DIV of the splitter pane it is in.

What methods are people using to get 100% height in all situations and browser resizes?
Nathan
Top achievements
Rank 2
 answered on 22 Apr 2013
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
Security
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
SegmentedControl
+? more
Top users last month
Boardy
Top achievements
Rank 2
Veteran
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
ivory
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ClausDC
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Boardy
Top achievements
Rank 2
Veteran
Iron
Benjamin
Top achievements
Rank 3
Bronze
Iron
Veteran
ivory
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ClausDC
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?