Telerik Forums
UI for ASP.NET MVC Forum
2 answers
164 views
I've got a grid that I need to select a color criteria for the data.  I've created a Custom Model that uses the ColorPickerFor component and when in the color cell the colorPicker appears and I can select a color.  When I tab off of the cell the color value is displayed as "#fff111" or whatever color I selected.  I don't want to display the values in the grid like that but want to display them as a square color swatch showing the color even when the cell is not in edit mode.  How can you accomplish this.  I've been fiddling with ClientTemplate and I can't seem to get the background-color to work.
Dimiter Madjarov
Telerik team
 answered on 02 Feb 2016
2 answers
85 views

Hi everyone,

 

I'm trying to add an EditorTemplate for an autocomplete column.  However, when I add the template, the only way for the grid to get populated is to select from the dropdown.  If I don't select from the dropdown, then the autocomplete does not populate the grid column with the text.  My code is below.   Any help is much appreciated.  Thank you for your time.

 

Bret Mullinix

 

Column From Grid -->


columns.Bound(l => l.AssetObject).Width(200)
                                        .ClientTemplate(" #: data.AssetObject ? data.AssetObject.SerialNumber : getSerialNumber(this, data) #" +
                                                        "<input type='hidden' name='ShipmentItems[#= index(data)#].AssetObject.AssetTypeId' " +
                                                            " value=' #: data.AssetObject ? data.AssetObject.AssetTypeId : '[None]' #' /> " +
                                                        "<input type='hidden' name='ShipmentItems[#= index(data)#].AssetObject.SerialNumber' " +
                                                            " value=' #: data.AssetObject ? data.AssetObject.SerialNumber : '[None]' #' /> " +
                                                        "<input type='hidden' name='ShipmentItems[#= index(data)#].AssetObject.Id' " +
                                                        "value='#: data.AssetObject ? data.AssetObject.Id : 0 #' />" +
                                                        "<input type='hidden' name='ShipmentItems[#= index(data)#].AssetObject.Responsible' " +
                                                        "value='#: data.AssetObject ? data.AssetObject.Responsible : '' #' />" +
                                                            "<input type='hidden' name='ShipmentItems[#= index(data)#].AssetObject.Disposition' " +
                                                        "value='#: data.AssetObject ? data.AssetObject.Disposition : '' #' />" +
                                                        "<input type='hidden' name='ShipmentItems[#= index(data)#].AssetObject.ResponsibleId' " +
                                                        "value='#: data.AssetObject ? data.AssetObject.ResponsibleId : 0 #' />" +
                                                            "<input type='hidden' name='ShipmentItems[#= index(data)#].AssetObject.DispositionId' " +
                                                        "value='#: data.AssetObject ? data.AssetObject.DispositionId : 0 #' />" +
                                                            "<input type='hidden' name='ShipmentItems[#= index(data)#].AssetObject.OwnerId' " +
                                                        "value='#: data.AssetObject ? data.AssetObject.OwnerId : 0 #' />"
                                        )
                                        .EditorTemplateName("AssetSerialNumberAutoComplete");

EditorTemplate:  AutoSerialNumberAutoComplete

@using Kendo.Mvc.UI
@using DataTransferObjects
@model AssetDTO
@(Html.Kendo().AutoComplete()  
        .Name("AssetSerialNumberAutoComplete")
             
          .DataTextField("SerialNumber")
          .Events(e => e.Change("onSerialNumberChange"))     
          .DataSource(source =>
          {
              source.Read(read =>
              {
                  read.Action("GetAssetBySerialNumber", "Asset").Data("onAdditionalDataForAssetSerialNumber");
              });
               source.ServerFiltering(true);
               
          })
              .HtmlAttributes(new { style = "width:100%", data_skip = "false", data_bind = "defferedValue: AssetObject" })
          .Filter("startswith")
          .MinLength(2)
          .Height(400)
         
               .HeaderTemplate("<div class=\"col-sm-12\">" +
                        "<div class=\"col-sm-6\">SerialNumber</div>" +
                        "<div class=\"col-sm-6\">Asset Type</div>" +
                    "</div><br/>")
              .Template("<div class=\"col-sm-12\">" +
                      "<div class=\"col-sm-6\">#: data.SerialNumber #</div>" +
                        "<div class=\"col-sm-6\">#: data.AssetType #</div>" +
                        "</div>")
          
)
 
<script>
 
    var autoComplete = $("#AssetSerialNumberAutoComplete").data("kendoAutoComplete");
    autoComplete.list.width(600); //adjust width of the drop-down list
 
</script>

Bret
Top achievements
Rank 1
 answered on 01 Feb 2016
6 answers
1.7K+ views

There are several topics on this forum regarding linking Grid columns to Dictionary properties. I've managed to do just that, but these columns are missing sorting and dropdown menu.

My model represents an issue from issue tracking system that may have very different fields depending on particular configuration. I can't see it feasible to define each possible property for my model class and the only logical solution is to have direct properties for most common fields and have a Dictionary for custom fields.

 

I'm using Kendo.MVC version 2016.1.112 in MVC 6 / .NET 5 project (which currently doesn't support server-side binding as far as I understand - rendering some solutions posted on this forum inapplicable). Browser is Chrome, but it doesn't seem the issue relates to browser version.

 

My model class is as follows:

public class Issue
{
    public string Key { get; set; }
    public string Summary { get; set; }
    public string Status { get; set; }
    public string StatusType { get; set; }
    public DateTime? Created { get; set; }
    public DateTime? LastUpdated { get; set; }
 
    public Dictionary<string, object> CustomProperties { get; set; } = new Dictionary<string, object>();
}

 

The Grid is then defined in View's *.cshtml file as this:

@(Html.Kendo().Grid<JIRAReports.Models.Issue>()
  .Name("grid")
  .HtmlAttributes(new { style = "margin-top: 10px;" })
  .DataSource(dataSource => dataSource.Ajax()
                                      .Sort(sort => sort.Add("LastUpdated").Ascending())
                                      .Read(read => read.Action("JiraIssues_Read", "Reports"))
                                      .PageSize(15)
 
              )
  .Columns(columns =>
  {
    columns.Bound(issue => issue.Key).Width(120).HtmlAttributes(new { style = "white-space: nowrap;" })
      .ClientTemplate($"<a href=\"{baseIssueUrl}#=Key#\" target=\"_blank\">#=Key#</a>");
    columns.Bound(issue => issue.Status).Width(150)
      .ClientTemplate(statusColumnTemplate);
    columns.Bound(issue => issue.Summary).HtmlAttributes(new { style = "white-space: nowrap;" });
    columns.Bound(issue => issue.LastUpdated).Width(180).HtmlAttributes(new { style = "white-space: nowrap;" })
      .Title("Last Updated").Format("{0:M/d/yyyy (ddd)}");
    //Adding custom properties
    columns.Template("#:CustomProperties['CustomProperty1']#").Title("Custom Property 1");
    columns.Template("#:CustomProperties['CustomProperty2']#").Title("Custom Property 2").Hidden();
  })
  .Pageable(config => config.PageSizes(new[] { 10, 15, 25, 100 })
                            .Refresh(true))
  .Sortable(config => config.AllowUnsort(false).SortMode(GridSortMode.MultipleColumn))
  .Scrollable(config => config.Height("895px"))
  .Resizable(config => config.Columns(true))
  .ClientDetailTemplateId("item-template")
  .ToolBar(tools => tools.Custom().Text("Expand All").Name("ExpandAll"))
  .ToolBar(tools => tools.Custom().Text("Collapse All").Name("CollapseAll"))
  .NoRecords()
  .ColumnMenu()
  .Reorderable(config => config.Columns(true))
  .Deferred()

 

The resulting grid is rendered as on the screenshot attached. You can see there is no dropdown next to columns linked to Dictionary's items, they are not sortable, but these columns do appear in dropdowns for other columns so they can be shown/hidden. But sorting on them is absolutely required.

 

Please suggest a solution. There must be a way to link to less structured data or indexer property, especially since all we need is to display it in read-only mode.

Siarhei
Top achievements
Rank 1
 answered on 01 Feb 2016
5 answers
100 views

I'm bundling all my updates into one request by using the method suggested in the example "GridSyncChangesWithOneRequest".

The actual call is: 

$.ajax({
    url: "/Home/UpdateCreateDelete",
    data: data,
    type: "POST",
    error: function () {
        //Handle the server errors using the approach from the previous example
    },
    success: function () {
        alert("update on server is completed");
        grid.dataSource._destroyed = [];
        //refresh the grid - optional
        grid.dataSource.read();
    }
})     

Mark
Top achievements
Rank 1
 answered on 29 Jan 2016
1 answer
242 views

When using TreeList widget with a simple model like this:

public class MyModel
{
     public int? Id {get;set;}
     public int? ParentId {get;set;}
     public string Name {get;set;}
}

...

@(Html.Kendo().TreeList<MyModel>().Name("treeList")
    .Toolbar(t=>t.Create())
    .Editable(e=>e.Mode("popup"))
    .DataSource(ds=>ds
          .Model(m=>
          {
               m.Id(f=>f.Id);
               m.ParentId(f=>f.ParentId);
               m.Field(f=>f.Name);
          })
         .Create(c=>c.Action("Create", "My"))
        )
        .Columns(c=>
        {
c.Add().Field(f=>f.Id);
c.Add().Field(f=>f.ParentId)
c.Add().Field(f=>f.Name)
        })
)

When filling the popup, there are no error, but the item is NOT inserted in the treeList. If I change the type of the Id and ParentId to non nullable, the problem is solved.

In your demo, the model seems to have nullable fields as Id and ParentId, but there are no demo of item creation. Is it a bug or something missing in my code?When using TreeList widget with a simple model like this:

public class MyModel
{
     public int? Id {get;set;}
     public int? ParentId {get;set;}
     public string Name {get;set;}
}

...

@(Html.Kendo().TreeList<MyModel>().Name("treeList")
    .Toolbar(t=>t.Create())
    .Editable(e=>e.Mode("popup"))
    .DataSource(ds=>ds
          .Model(m=>
          {
               m.Id(f=>f.Id);
               m.ParentId(f=>f.ParentId);
               m.Field(f=>f.Name);
          })
         .Create(c=>c.Action("Create", "My"))
        )
        .Columns(c=>
        {
c.Add().Field(f=>f.Id);
c.Add().Field(f=>f.ParentId)
c.Add().Field(f=>f.Name)
        })
)

When filling the popup, there are no error, but the item is NOT inserted in the treeList. If I change the type of the Id and ParentId to non nullable, the problem is solved.

In your demo, the model seems to have nullable fields as Id and ParentId, but there are no demo of item creation. Is it a bug or something missing in my code?

 

Regards

Alex Gyoshev
Telerik team
 answered on 29 Jan 2016
1 answer
238 views
 
 
 
 
@(Html.Kendo().Grid<AMCUpfrontTracker2.Models.AccountsViewModel>()
      .Name("kGrid")
      .Columns(columns =>
      {
          columns.Bound(c => c.AccountID).Visible(false);
          columns.Bound(p => p.Agency).ClientTemplate("#=Agency.AgencyName#").Width(220);
          columns.Bound(c => c.Advertiser).ClientTemplate("#=Advertiser.AdvertiserName#").Width(220);
          columns.Bound(c => c.AccountName).Width(220);
          columns.Bound(c => c.Net).ClientTemplate("#=Net.Network#").Width(200);
          //columns.Bound(c => c.BuyCode).ClientTemplate("#=BuyCode.BuyCode#").Width(100);
          columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
      })
       .ToolBar(toolBar =>
       {
           toolBar.Create();
       })
      .Editable(editable => editable.Mode(GridEditMode.InLine))
      .Scrollable()
      .Pageable(pageable => pageable
      .Refresh(true)
      .PageSizes(new List<object> { 10, 20, 50, "All" })
      .ButtonCount(5))
      .Sortable()
      .Filterable()
      .ColumnMenu()
      .HtmlAttributes(new { style = "height:600px;" })
      .DataSource(dataSource => dataSource
          .Ajax()
          .ServerOperation(false)
          .Events(events => events.Error("grid_error")) // Handle the "error" event
          .Events(events => events.RequestEnd("requestEndHandler"))
         .Model(model =>
         {
             model.Id(p => p.AccountID);
             model.Field(p => p.AccountID).Editable(false);
             model.Field(p => p.Agency).DefaultValue(
                ViewData["defaultAgency"] as AMCUpfrontTracker2.Models.AgencyViewModel);
             model.Field(p => p.Advertiser).DefaultValue(
                ViewData["defaultAdvertiser"] as AMCUpfrontTracker2.Models.AdvertiserViewModel);
             model.Field(p => p.Net).DefaultValue(
                ViewData["defaultNetwork"] as AMCUpfrontTracker2.Models.NetworkViewModel);
             //model.Field(p => p.BuyCode).DefaultValue(
             //   ViewData["defaultBuyCode"] as AMCUpfrontTracker2.Models.BuyCodesViewModel);
         })
 
          .Read(read => read.Action("Accounts_Read", "ManageAccounts").Data("additionalInfo"))
          .Create(create => create.Action("Accounts_Create", "ManageAccounts"))
          .Update(update => update.Action("Accounts_Update", "ManageAccounts"))
          .Destroy(destroy => destroy.Action("Accounts_Destroy", "ManageAccounts"))
      )

 

 

Filter option is working with columns not having clientTemplates like AccountName but not in others.

 
 
Dimiter Madjarov
Telerik team
 answered on 29 Jan 2016
1 answer
137 views

In synchronous mode, it's easy to take a server side action when all files are processed via foreach (var file in files), when it is completed. But how to do this in async mode? The server controller has no notion of the total number of files. And I don't see an Event fired when all the files are upload, although the control has the "Done" UI indication.

 

thanks, Tom

 
Dimiter Madjarov
Telerik team
 answered on 29 Jan 2016
2 answers
1.0K+ views

I'm creating a grid for a model that has child relationship that is not required.  The grid displays when the child has a value but if the child is null then I get a message that a value can't be null.  For example.   If my model is:

public class ProjectTypeViewModel
{
     [Column("ManpowerProjectTypeID")]
     public int ID { get; set; }

     [StringLength(50)]
     [Display(Name = "Project Type")]
     public string ProjTypeDesc { get; set; }

     [UIHint("ClientProjectType")]
     public ProjectTypeComboViewModel ParentProjectType { get; set; }
}

public class ProjectTypeComboViewModel
{
     [Column("ManpowerProjectTypeID")]
     public int ID { get; set; }

      [StringLength(50)]
      [Display(Name = "Project Type")]
      public string ProjTypeDesc { get; set; }

Then my grid looks like:

@(Html.Kendo().Grid<ManpowerForecast.Web.ViewModels.ProjectTypeViewModel>()
.Name("gridProjectType")
.Columns(columns =>
{
   columns.Bound(c => c.ProjTypeDesc).Width(200);
   columns.Bound(c => c.ParentProjectType).ClientTemplate("#=ParentProjectType.ProjTypeDesc#")
          .Width(150);
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.HtmlAttributes(new { style = "height: 550px" })
.Refresh(true)
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{

     model.Id(prop => prop.ID);
     model.Field(b => b.ParentProjectType).DefaultValue(ViewData["defaultProjectTypes"] as ProjectTypeComboViewModel);
})
.Create(create => create.Action("CreateManpowerProjectTypes", "Manpower"))
.Read(read => read.Action("ReadManpowerProjectTypes", "Manpower"))
.Update(edit => edit.Action("UpdateManpowerProjectTypes", "Manpower"))
.Destroy(delete => delete.Action("DestroyManpowerProjectTypes", "Manpower"))
.PageSize(20)
)
)

 

this displays just fine as long as ParentProjectType has a value but if it is null I get an error in the browser consul that reads: ProjTypeDesc is null.  If I comment out all the lines that have to do with the ParentProjectType the grid will display the data but off course doesn't contain the parent project type field.  How do I indicate in the grid that the data isn't required or is nullable?

 

 

Viktor Tachev
Telerik team
 answered on 29 Jan 2016
1 answer
127 views

I am trying to bind a grid in the editor template that contains List<> and have the ability to add and edit this list I need to do this in multiple places so Any idea would help a lot.

Model:

public int AgencyId { get; set; }
public string AgencyName { get; set; }
public int AgencyNumber { get; set; }
public string TIN { get; set; }
public bool Incorp { get; set; }
public string Affiliat { get; set; }
public IList<AgencyLocation> AgencyLocationCollection 

 Cshtml

<individual Field edits>

Need a grid here that will show all the associate locations and allow add and edit

  @(Html.Kendo().Grid<AgencyLocation>()
.Name("Grid")
.EnableCustomBinding(false)
.BindTo(Model.AgencyLocationCollection)
.Columns(columns =>
{
columns.Bound(m => m.AddressShortString);
columns.Bound(m => m.AgencyLocationId);
})
)

 

 

 

 

Dimo
Telerik team
 answered on 29 Jan 2016
1 answer
178 views

I'm using a Kendo UI Grid in conjunction with two AutoComplete widgets.  Everything mostly works perfectly, however, if a user pages through the grid and then does a search using one of the AutoComplete widgets, the grid does not display the data.  The pager at the bottom of the grid is updated but the grid is blank.  The user must click on a page before the data is displayed.  I have not been able to find a setting to resolve this despite hours of Googling.  Here's the code for my grid: 

@(Html.Kendo().Grid(Model)
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(a => a.EmployeeOI).Visible(false);
            columns.Bound(a => a.DepartmentOI).Visible(false);
            columns.Bound(a => a.LevelId).Width(60).Title("Level");
            columns.Bound(a => a.DepartmentName).Width(150).Title("Department");
            columns.Bound(a => a.EmployeeId).Width(60).Title("Emp");
            columns.Bound(a => a.BuyerName).Width(100).Title("Buyer Name");
            columns.Bound(a => a.MinAmount).Width(100).Title("Min Amt");
            columns.Bound(a => a.MaxAmount).Width(100).Title("Max Amt");
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
        })
        .ToolBar(toolbar => toolbar.Create())
        .Editable(editable => editable.Mode(GridEditMode.PopUp))
        .Pageable()
        .Sortable(s => s
            .AllowUnsort(false)
            .SortMode(GridSortMode.MultipleColumn))
    .Scrollable()
    .HtmlAttributes(new { style = "height:650px;, width:100%" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .Sort(x => x.Add(y => y.LevelId).Ascending())
        .Sort(x => x.Add(y => y.MaxAmount).Ascending())
        .ServerOperation(false)
        .PageSize(8)
        .Events(events => events.Error("error_handler"))
        .Read(read => read.Action("Read", "Home").Data("gridAddlData"))
        .Create(update => update.Action("EditingPopup_Create", "Home"))
        .Update(update => update.Action("EditingPopup_Update", "Home"))
        .Destroy(update => update.Action("EditingPopup_Destroy", "Home"))
      .Model(m =>
      {
          m.Id(i => i.Id);
          m.Id(i => i.EmployeeOI);
          m.Id(i => i.DepartmentOI);
          m.Field("LevelID", typeof(string));
          m.Field("EmployeeId", typeof(string));
          m.Field("BuyerName", typeof(string));
          m.Field("MinAmount", typeof(decimal));
          m.Field("MaxAmount", typeof(decimal));
          m.Field("DepartmentId", typeof(string));
      })
      )
    )

Radoslav
Telerik team
 answered on 29 Jan 2016
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
Upload
ComboBox
MultiSelect
Window
ListView
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
Barcode
ButtonGroup (Mobile)
Drawer (Mobile)
ImageEditor
RadioGroup
Sparkline
Stepper
TabStrip (Mobile)
GridLayout
Template
Badge
LinearGauge
ModalView
ResponsivePanel
TextArea
Breadcrumb
ExpansionPanel
Rating
ScrollView
ButtonGroup
CheckBoxGroup
Licensing
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
AICodingAssistant
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
+? more
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?