Telerik Forums
UI for ASP.NET MVC Forum
6 answers
1.2K+ views

Hi,

I am new to using KendoUI and am sorry if this has been answered before but I cannot seem to find an answer that works for me. I have a search button and a grid on the page. I am taking to d.3 in the backend (a DMS system) using library calls. The user enters s/he search query in the field and I call the Read method in my Controller to get the data from d.3. What is happening is that I am getting the data back in the request but the grid is not updating.

Here is my MVC code:

@(Html.Kendo()
    .Grid(Model)
    .Name("grid")
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Read(r => r.Action("Read", "Search"))
    )
    .Filterable(f => f.Mode(GridFilterMode.Row))
    .Columns(columns =>
    {
    {
        columns.Bound(c => c.DocumentType)
            .Filterable(false)
            .Width("150px")
            .Title(@Localizer["SearchTableHeaderDocumentType"]);

        columns.Bound(c => c.DocumentTypeLong)
            .Filterable(true)
            .Title(@Localizer["SearchTableHeaderDocumentTitle"])
            .Filterable(ftb => ftb.Cell(cell => cell.Operator("contains").SuggestionOperator(FilterType.Contains)));

    })
    )

I have a button on the page that does the submit using the following code:

   var search = $("#search-field").val();
    if (!search) return;
    if (search.trim() === "") return;
    var dataSource = $("#grid").data("kendoGrid").dataSource;
    var parameters = {
        searchFor: search
    }

    // call the search passing the parameters -> searchFor is the parameter name on the SearchController/Read method
    dataSource.read(parameters);

 

This calls my Read method in the SearchController.cs. The Search method creates the data that is supposed to be passed back to the Grid: 

 

            // setup your result for KendoUI
            DataSourceResult result = model.Entries.ToDataSourceResult(request);

            // return
            return Json(result);

I also see the data structure in the response if I check the event after the RequestEnd:

            .Events(events => events.RequestEnd("onRequestEnd"))

or if I check the response in Chrome - this is what I get:

+0Object {DocumentId: "GD00000016", DocumentType: "D3CHG", DocumentTypeLong: "D.3 :: Fehler/Request", …}Object
+1Object {DocumentId: "GD00000148", DocumentType: "DEPSU", DocumentTypeLong: "Abteilung :: Leitung", …}Object
+2Object {DocumentId: "GD00000149", DocumentType: "DEPSU", DocumentTypeLong: "Abteilung :: Leitung", …}Object
+3Object {DocumentId: "GD00000150", DocumentType: "DEPSU", DocumentTypeLong: "Abteilung :: Leitung", …}Object
+4Object {DocumentId: "GD00000266", DocumentType: "IDOCU", DocumentTypeLong: "Infrastruktur :: Handbuch", …}Object
+5Object {DocumentId: "GD00000267", DocumentType: "IDOCU", DocumentTypeLong: "Infrastruktur :: Handbuch", …}Object
+6Object {DocumentId: "GD00000268", DocumentType: "IDOCU", DocumentTypeLong: "Infrastruktur :: Handbuch", …}Object
+7Object {DocumentId: "GD00000269", DocumentType: "CKNOW", DocumentTypeLong: "Global :: Wissen", …}Object
+8Object {DocumentId: "GD00000277", DocumentType: "IDOCU", DocumentTypeLong: "Infrastruktur :: Handbuch", …}Object

 

very odd. 

 

Maybe this helps: If I return dummy data from the Index method (I am currently returning an empty list  => return View(new List<SearchEntryModel>());) before using the Read method from the grid everything magically works (except that the number of entries is limited to the return from the Index method). 

 

Sorry about the weird explanation but I don't know how to better explain it. 

 

Thank you in advance

Martin



 

 

n/a
Top achievements
Rank 1
 answered on 01 Jul 2019
5 answers
797 views
Kendo grid inline edit mode resulting an editable row with narrow controls which don't have any kendo styles. Please let me know the possible solution  to resolve this.
Eyup
Telerik team
 answered on 01 Jul 2019
6 answers
6.7K+ views
Hi,

I have an application that is strictly used in the central time zone.  Our web server is on pacific time zone.  Data is passed to the web server from the central time zone and I want to display it this way.  Every non-kendo control shows the time as is.  The kendo grid is showing the date with an adjustment of +2 hours so it appears there is a conversion - which I do not want.

My column format is as follows:
c.Bound(g => g.LastUpdated).Format("{0:MM/dd/yyyy hh:mm tt}")

Is it possible to tell the grid to show the date/time "as is"?

Thanks,
David A.
Tsvetomir
Telerik team
 answered on 28 Jun 2019
1 answer
88 views
I have been searching for an hour or so to find the code used in the Chart API demo and I could not find it in the github for the rest of the demos.  I am wondering where that code is located.
Viktor Tachev
Telerik team
 answered on 27 Jun 2019
10 answers
484 views
Having grid with 2 foreign key columns. Grid shows them as is should - value from foreign column (matched by ID)

But in edit mode I have Integer field instead of drop down in one of them.

Models and EditTemplate absolutely identical (as I see)
Problem is in Teachers

Here is models

   [DisplayName("Level")]
        [UIHint("Level")]
        public int LevelId
        {
            get;
            set;
        }

        [DisplayName("Teacher")]
        [UIHint("Teacher")]
        public int TeacherId
        {
            get;
            set;
        }

here is Level.cshtml
@model object
           
@(
 Html.Kendo().DropDownListFor(m => m)
                        .BindTo((System.Collections.IEnumerable)ViewData["levels"]).DataTextField("Title").DataValueField("Id")
)


here Teacher.cshtml
@model object
           
@(
 Html.Kendo().DropDownListFor(m => m)
                            .BindTo((System.Collections.IEnumerable)ViewData["teachers"]).DataTextField("Name").DataValueField("TeacherId")
)

also
ViewData["teachers"]) populated as
  var dataContext = new EntitiesModel();
            var items = dataContext.Peoples
                        .Select(c => new TeachersViewModel
                        {
                            TeacherId = c.HumanId,
                            Name = c.nme + " " + c.Surname,
                            OccupationId = c.OccupationId
                        }).Where(p => p.OccupationId == 2)
                        .OrderBy(e => e.Name);
            ViewData["teachers"] = items;
            ViewData["defaulteacher"] = items.First();

Still do`nt get why one of column don want to be dropdown
GarfieldTech
Top achievements
Rank 1
 answered on 26 Jun 2019
1 answer
669 views

Hi

I have based the following code on Grid / Custom command
https://demos.telerik.com/aspnet-mvc/grid/custom-command


@(Html.Kendo().Grid<MyProject.Models.Profiles>().
    Name("MyTable").
    Columns(columns =>
    {
        columns.Command(command => {
            command.Custom("Edit Details").Click("EditDetails");
        }).Width(120);
    })
    .HtmlAttributes(new { style = "height: 600px" })
    .BindTo(Model)
    .Scrollable()
    .Groupable()
    .Sortable()
    .Filterable()
)
 
<script>
    function EditDetails(e) {
        e.preventDefault();
    }
</script>

When I run the code I get the following error in the Developer Console(Edge & Chrome)
Uncaught ReferenceError: EditDetails is not defined

I have been unable to find the problem, any suggestions?

Is there a way that i can call a controller method without going through javascript?

 

Thanks

Marin Bratanov
Telerik team
 answered on 26 Jun 2019
1 answer
451 views

Hello,

I have this autocomplete in my view :

@(Html.Kendo().AutoComplete()
        .Name("description.EmplacementEquipementAutreSpecifier")
        .DataTextField("EmplacementEquipementAutreSpecifier")
        .Filter("contains")
        .MinLength(3)
        .HtmlAttributes(new { style = "width:100%;", @class = "form-control" })
        .DataSource(source =>
        {
            source
            .Read(read =>
            {
                read.Action("GetEmplacementEquipementAutreSpecifier", "Description");
            })
        .ServerFiltering(false);
        })
        .Value(Model.description.EmplacementEquipementAutreSpecifier)
        .Events(e => e.Filtering("OnChangeNoEmplacementEquipement").Close("OnChangeNoEmplacementEquipement"))
)

And need to apply a Bootstrap style (class="form-control").  See result in attachment.  

When I remove some style I can see the reason of the missing bottom blue border.  The input box seem a bit lower compare to the thing that make the blue border.

Any suggestion to correct this issue?  Css probably.

 

 

Martin
Telerik team
 answered on 25 Jun 2019
7 answers
603 views

Hello,

I have a ui grid with code to hide the destroy button if only one record left in the grid:

...

columns.Command(command => { command.Destroy().Visible("isLastRecordEmail").Text("Remove"); }).Width(200);

...

                                            function isLastRecordEmail(e) {
                                                return $('\#GridEmails').data('kendoGrid').dataSource.data().length > 1;
                                            }

But if I click the Add button then a new records appears and destroy button will appear for last record to allow to delete the very last record.

My question is, how to hide the destroy button in this case?

I did try to add code:

 function isLastRecordEmail(e) {
      if ($('\#GridEmails').EditIndexes.Count > 0) return false;

but EditIndexes is undefined.

Could you please help?

Thanks!

Andrey
Top achievements
Rank 1
Veteran
 answered on 25 Jun 2019
1 answer
8.7K+ views

CostCenterController:

public ActionResult CostCenters_Read([DataSourceRequest] DataSourceRequest request)         {             return Json(ccService.Read().ToDataSourceResult(request));         }         [AcceptVerbs(HttpVerbs.Post)]         

public ActionResult CostCenters_Create([DataSourceRequest] DataSourceRequest request, CostCenterViewModel cc)         {             if (cc != null && ModelState.IsValid)             {                 ccService.Create(cc);             }             //return Json(cc, JsonRequestBehavior.AllowGet);             return Json(new[] { cc }.ToDataSourceResult(request, ModelState));         }         [AcceptVerbs(HttpVerbs.Post)]         

public ActionResult CostCenters_Update([DataSourceRequest] DataSourceRequest request, CostCenterViewModel cc)         {             if (cc != null && ModelState.IsValid)             {                 ccService.Update(cc);             }             return Json(new[] { cc }.ToDataSourceResult(request, ModelState));         }

 

Index.cshtml:

@(Html.Kendo().Grid<Main.Models.Quality.CostCenterViewModel>()                            

                                   .Name("CostCenter")                            

                                   .Columns(columns =>                            

                                    {columns.Bound(c => c.CostCenterID);                                

                                     columns.Bound(c => c.CC).Width(140);                                

                                     columns.Bound(c => c.Rate).Width(140);                                

                                     columns.Bound(c => c.Date).Width(100);                                

                                     columns.Command(command => command.Destroy()).Width(110);                            

                                     })                            

                                    .ToolBar(toolbar => toolbar.Create())                             

                                    .Editable(editable => editable.Mode(GridEditMode.PopUp))                            

                                    .Pageable()                            

                                    .Sortable()                            

                                     .Scrollable()                            

                                     .HtmlAttributes(new { style = "height:550px;" })                            

                                     .DataSource(dataSource => dataSource                            

                                     .Ajax()                            

                                     .PageSize(20)                            

                                     .Events(events => events.Error("error_handler"))                            

                                     .Model(model => model.Id(c => c.CostCenterID))                            .Create(update => update.Action("CostCenters_Create", "CostCenter"))                            .Read(read => read.Action("CostCenters_Read", "CostCenter"))                            .Update(update => update.Action("CostCenters_Update", "CostCenter"))                            .Destroy(update => update.Action("CostCenters_Destroy", "CostCenter"))                            

                            ))               

                            <script type="text/javascript">                    

                                   function error_handler(e) {                       

                                           if (e.errors) {                            

                                           var message = "Errors:\n";                            

                                      $.each(e.errors, function (key, value) {                                

                                           if ('errors' in value) {                                    

                                      $.each(value.errors, function () {                                     

                                       message += this + "\n";                                   

                                       });                                

                                     }                            

                                  });                            

                                 alert(message);  }                    

                                   }                

                                  </script>

I set CostCenterServer, the code is similar as ProductService.

It show up as normal, but when I Click "New Record", It popped up error with "This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet."

 

In Controller, i tried to replace return Json(cc, JsonRequestBehavior.AllowGet); with return Json(new[] { cc }.ToDataSourceResult(request, ModelState)); but no lucky??

Georgi
Telerik team
 answered on 25 Jun 2019
1 answer
106 views

Hello,

What is the best practice to use Kendo UI grid with "long run" server side data source? I have a web page with two tabs. The grid in on second page. The data downloaded on login process and average time is about 20-30 seconds, that's not good. If I create remote data source then opening the second tab is taking 20 seconds to display the grid content.If I choose the first tab and then return the second tab then the grid takes 20 seconds again.

The amount of records in the data source is 0-5. The problem is that SQL code has to check too many things (and controller accessing another web site) and cannot be optimized.

Should I go with web workers? In this case the data could be downloaded when the first tab is displaying. Or might be exist another solution? Or something already in grid functionality that I have missed? What is the best practice for such case?

Thanks!

Andrey
Top achievements
Rank 1
Veteran
 answered on 24 Jun 2019
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
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
+? 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?