Telerik Forums
UI for ASP.NET MVC Forum
13 answers
1.4K+ views

Hi, 

I'm creating grid with dynamic model structure. But i could not use ForeignKey for dropdowns.

i'am using same viewdata method for non-dynamic grid structure and its working. Because i know model name and model tree.

I want to use dropdowns with dynamic grid structure.

var countries = _adminBusinessLayer.Get("sys_Address_Countries"); //Countries for dropdown
ViewData["Countries"] = countries;
 
@(Html.Kendo().Grid<dynamic>()
      .Name("Grid")
      .Columns(columns =>
      {
          foreach (System.Data.DataColumn column in Model.Columns)
          {
              var c = columns.Bound(column.ColumnName);
              if (column.ColumnName == "CountryID")
              {
                  //columns.ForeignKey(d => d.CountryID, (System.Collections.IEnumerable)ViewData["Countries"], "CountryID", "countryNameTr").HeaderTemplate("<i class='fa fa-user'></i> Country");
              }
          }
 
...
John
Top achievements
Rank 1
 answered on 15 Aug 2018
5 answers
1.7K+ views
Hi All,

I'm having problems when trying to add a clickable hyperlink to my header template on my grid. The idea is to add a hyperlink with the text of ClientName from the dataitem that will call my controller and pass the ClientCode of the underlying data item.

 
.Columns(columns =>
{
    columns.Bound(u => u.ClientName)
           .ClientGroupHeaderTemplate(Html.ActionLink("\"<#= ClientName#>\"", "blalbalba", "blabla", new { clientCode = "<#= ClientCode #>" }).ToString());
    columns.Bound(u => u.Status).Width("50px").Title("Collat").ClientTemplate("<i class='#= Status ? 'fa fa-check fa-3x red-text' : 'fa' #'/>");
    columns.Bound(u => u.Quantity).Width("100px");
    columns.Bound(u => u.Security).Title("Security");
    columns.Bound(u => u.Value).Format("{0:C}")
        .ClientGroupFooterTemplate("#=kendo.toString(sum, '£0.00') #")
         .ClientFooterTemplate("#= kendo.toString(sum, '£0.00') #").Width("100px");
    columns.Bound(u => u.CollatValue).Format("{0:C}")
        .ClientGroupFooterTemplate("#=kendo.toString(sum, '£0.00') #")
        .ClientFooterTemplate("#= kendo.toString(sum, '£0.00') #").Title("Collat. Value").Width("100px");
 
})
.NoRecords("No records found")
.Pageable(pageable => pageable.Refresh(true))
.Sortable()
.Navigatable()
.AutoBind(true)
.DataSource(dataSource => dataSource
.Ajax()
.Aggregates(aggregates =>
{
    aggregates.Add(p => p.Value).Sum();
    aggregates.Add(p => p.CollatValue).Sum();
}).Group(group => group.Add(x => x.ClientName))
.PageSize(100)

 

cheers

Tsvetina
Telerik team
 answered on 15 Aug 2018
1 answer
943 views

Hi Team,

I have a custom add new row button on each row, which adds a new row adjacent to the current row which works fine with the below js code:

        var grid = $("#grid").data("kendoGrid");
        customRowDataItem = this.dataItem($(e.currentTarget).closest("tr"));
        currentCommissionMemoId = customRowDataItem.uidCommissionMeemoBusiness;

        var idx = grid.dataSource.indexOf(customRowDataItem);
        console.log(idx);

        var newItem = grid.dataSource.insert(idx, {});
        var newRow = grid.items().filter("[data-uid='" + newItem.uid + "']");
        grid.editRow(newRow);

 

The issue is, I am trying to do the same after grouping the grid data using the drag and drop grouping option. The add new row acts weird after grouping,

1. New row is not added adjacent to the current row

2. When trying to add a new row in a different page (grid is pageable), does not add a new row at all. 

My primary intention is to add a new row inside the group after grouping the kendo grid data, is this possible?

 

Thank you in advance,

Sam

 

 

Tsvetina
Telerik team
 answered on 15 Aug 2018
5 answers
198 views

Hello,

I would like to know if i can add an ActionLink in a column in my DetailTemplate: 

The only way I've found is by using a Template , for exemple : 

 

 

.Columns(col => {

      col.Bound(p => p.Etat).Template(@<text>@Html.ActionLink("Edit", "Edit")</text>);

})

 

 

But like i'm already in a DetailTemplate , i get an error when i try to do this :

 

 

.DetailTemplate(
            @<text>
             @(Html.Kendo().Grid<Affaire>()
                       .Name("Affaires_" + item.Id)
                       .Columns(col => {
                                                    col.Bound(p => p.Name).Template(@<text>@Html.ActionLink("Edit", "Edit")

             </text>)

 

Is there another way to make this link work ?

Thanks

 

Attila Antal
Telerik team
 answered on 15 Aug 2018
5 answers
1.6K+ views
Hi,

We are using KendoGrid in "inCell" mode with "Batch" mode enabled and according to telerik examples we've created our model like following :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace webArta.Models
{
    public class ASoratModel
    {
 
        public long id { get; set; }
        public String name { get; set; }
        public String title { get; set; }
 
    }
}

Then I've create my BLL as following :
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
 
namespace webArta.Models
{
    public class ASoratService
    {
        private String sqlCnStr = functions.GetConnectionString(false);
        public List<ASoratModel> Read()
        {
            List<ASoratModel> data = new List<ASoratModel>();
            using (SqlConnection connection = new SqlConnection(sqlCnStr))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("select * from [test]", connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (reader.Read())
                        {
                            ASoratModel m = new ASoratModel();
                            m.id = (long)reader["id"];
                            m.title = (string)reader["title"];
                            m.name = (string)reader["name"];
                            data.Add(m);
                        }
                    }
 
                }
            }
            return data;
        }
 
        public void Create(ASoratModel model)
        {
 
            model.name = "";
            model.title = "";
            String sql =
                "INSERT INTO [test] (name,title) VALUES ('" + model.name + "','" + model.title + "')";
            using (SqlConnection connection = new SqlConnection(sqlCnStr))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.ExecuteNonQuery();
                }
            }
 
        }
 
 
 
        public void Update(ASoratModel model)
        {
            String sql =
               "update [test] set name='" +model.name+"',title='"+model.title+"' where id="+model.id;
            using (SqlConnection connection = new SqlConnection(sqlCnStr))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.ExecuteNonQuery();
                }
            }
        }
 
 
 
        public void Delete(ASoratModel model)
        {
 
        }
 
    }
}

and my controller as following :
  public ActionResult Read([DataSourceRequest] DataSourceRequest request)
        {
 
            return Json(aSoratService.Read().ToDataSourceResult(request));
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
       
 
         [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Update([DataSourceRequest] DataSourceRequest request,
            IEnumerable<ASoratModel> asorats
){
             foreach(var item in asorats)
             {
                 aSoratService.Update(item);
             }
     
 
    return Json(asorats.ToDataSourceResult(request,ModelState));
 
         }
        

and this is my view :
@using webArta.Models
@using System.Linq
@using System.Data
 
 @(Html.Kendo().Grid<webArta.Models.ASoratModel>()
              .Name("grid")
 
              .Columns(columns =>
              {
                  columns.Bound(p => p.name);
                  columns.Bound(p => p.title);
                  //columns.Command(c =>
                  //{
                  //    c.Edit();
                  //    c.Destroy();
                  //});
 
              })
              .ToolBar(t =>
              {
                  t.Save();
                  t.Create();
 
 
              })
 
                 
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .AutoSync(true)
                  .Batch(true)                  
 
                         .Model(m => m.Id(p => p.id))
                  .Read(r => r.Action("Read", "MY_CONTROLLER"))
                             .Create(update => update.Action("Create", "MY_CONTROLLER"))
 
                                    .Update(update => update.Action("Update", "MY_CONTROLLER"))
                    .Destroy(update => update.Action("EditingInline_Destroy", "MY_CONTROLLER"))
                  .ServerOperation(true)
 
 
              )
 
              .Navigatable()
               
                       .Pageable()
                      .Sortable()
                              .Editable(ed =>
                              {
 
                                  ed.Mode(GridEditMode.InCell);
                                  ed.CreateAt(GridInsertRowPosition.Bottom);
 
                              })
 
 
 
 
                      .Scrollable()
                      .Filterable()
                       
 
                    .Resizable(resize => resize.Columns(true))
      )

yet when we try to update the data inside the Grid the Update method will get null value for it's second argument (IEnumerable<ASoratModel> asorats) but when we omit the IEnumerable<T> we only get one item.

we want need to get collection of all items when they are updated for showing them correctly in the Grid.

We are confused since we can't find any clue where are we doing wrong.
One thing to note : we don't have any ViewModel class it is all we have that I've copied here.
Georgi
Telerik team
 answered on 15 Aug 2018
3 answers
333 views
     Is there a way to have the pop up editor only call the update command on an edited item when the update button is pressed on the popup? It looks like when they click in the next field to update the previous field calls the update command and it causes a lot of database overhead/ time waste if there are multiple fields that need to be updated. I may be missing something or my update code is messy (which it is) but it seems like I should be able to only have the one write back to the model instead of one after every field change.
Mark
Top achievements
Rank 1
 answered on 14 Aug 2018
1 answer
211 views

Hi,

In my html page I use a grid with virtual scroll:

Html.Kendo().Grid<dynamic>(). ....

.DataSource(dataSource => dataSource
    .Ajax()
    .Read( read => read.Action(....))

.Scrollable(scroll =>
    {
            scroll.Height("100%");
            scroll.Virtual(true);
        }) ...

Everything works fine except for  :

- a special request (filter)

- Only on IE11 (It's OK for Chrome, FF & Edge)

In this case, my browser freezes.

I launched an analysis and it would seem that there is an javascript infinite loop (see attachment)

If I remove the virtual scroll, everything works properly

 

Regards

 

Milena
Telerik team
 answered on 14 Aug 2018
4 answers
1.0K+ views

How would I execute a custom function when any date has been selected? 

I searched for examples, but couldn't find a function that takes into consideration dynamic datepicker ID/class.

Can we add a custom function here without using Events? Or if we have to use events, can we pass the datepicker id/class to the function -- if so how?

My markup:

@(Html.Kendo().DatePicker()
                                        .Name(@Model.Name)
                                        .Footer("Today - #= kendo.toString(data,'ddd, MMM dd, yyyy') # ")
                                        .Min("1/1/1900")
                                        .Max("1/1/2200")
                                        .Events(e => e.Close("onClose"))
                                    //.Enable((Model.SelectedValues != null && Model.SelectedValues.Length > 0) || !Model.AllowNullValue)
                                    .Value(string.IsNullOrEmpty(Model.SelectedValues)
                                            ? null
                                            : Model.SelectedValues
                                                    .Replace("[OneMonthAgo]", DateTime.Now.AddMonths(-1).Date.ToString())
                                                    .Replace("[OneYearAgo]", DateTime.Now.AddYears(-1).Date.ToString())
                                                    .Replace("[CurrentDate]", DateTime.Now.Date.ToString())
                                                    )
                                    .HtmlAttributes(new { AllowNullValue = Model.AllowNullValue.ToString().ToLower(), Prompt = Model.Prompt, onblur = "DatePickerChangeHandler(this)", Class = "DatePicker" })
 
                                    )
Alex Hajigeorgieva
Telerik team
 answered on 13 Aug 2018
3 answers
383 views




 

 

 

 

 

 

 

HI

Everyone always ask how to delete the record,
But my question is : 

How to get the destroyed data items from the Grid's dataSource ?
Is there have any official/public method or property ? 

Best regards

Chris

 

 

Alex Hajigeorgieva
Telerik team
 answered on 13 Aug 2018
3 answers
574 views

HI

dataBound
Fired when the widget is bound to data from its data source.

But why the Destroy command trigger the dataBound event too ??? 

*XXXXX_Read method not executed while the Destroy command clicked.

-- 

Incell mode

    @(Html.Kendo().Grid<MyCompany.Entity.Models.TXXXXX>)
      .Name("XXXXXGrid")
      ...
      .Pageable(pageable => pageable.Enabled(false))
      .Columns(columns =>
      {
        ...
        columns.Command(command => command.Destroy().Text("Delete")).Width(100);
      })
      .DataSource(dataSource =>
      {
        dataSource
          .Ajax()
          .Batch(true)
          //.PageSize(GridConst.PAGE_SIZE)
          .Model(model =>
          {
            model.Id(m => m.UniqueID);
          })
          .ServerOperation(false)
          .Read(read => read.Action("XXXXX_Read", "XXX").Data("xxxxx.filterXXXXXGrid"))
          .Events(events =>
          {
            ...
          });
      })
      .Events(events =>
      {
        events.Change("xxxxx.XXXXXGrid_Change");
        events.DataBound("xxxxx.XXXXXGrid_DataBound");
        events.Edit("xxxxx.XXXXXGrid_Edit");
      })
      .HtmlAttributes(new { @style = "height: 100%; min-height: 180px" }))

*Visual Studio 2015
*Telerik DevCraft 2017.2.621.545 (UI for ASP.NET MVC).

Best regards

Chris

 

 


Georgi
Telerik team
 answered on 13 Aug 2018
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
DropDownButton
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
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
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Tien
Top achievements
Rank 1
Iron
Krasimir
Top achievements
Rank 3
Bronze
Iron
Iron
Cedar
Top achievements
Rank 1
Iron
Emil
Top achievements
Rank 1
Iron
Kyle Watson
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?