Telerik Forums
UI for ASP.NET MVC Forum
2 answers
428 views

Hello,

here is another case where I get dates picked corretly but when posted to the server the date is one day behind the picked date.

I have placed a single grid in a razor view. The first field (TestItem) of the grid  is populated with a custom dropdown-editor and the 2nd field (TestDate) with a custom dateEditor. The grid itself uses api-controller CRUD actions.

<div class="full-height full-width">
    <div id="sample-grid" class="full-height"></div>
</div>
 
@section scripts {
    <script type="text/javascript">
 
    function ItemDropDownEditor(container, options) {
        $('<input required data-text-field="System" data-value-field="Code" data-bind="value:' + options.field + '"/>')
            .appendTo(container)
            .kendoDropDownList({
                autoBind: false,
                dataSource: gridDataSource(actions.sample.getTestItems, 50)
            });
    }
 
    function TestdateEditor(container, options) {
        $('<input data-text-field="' + options.field + '" data-value-field="' + options.field + '" data-bind="value:' + options.field + '" data-format="' + options.format + '"/>')
                .appendTo(container)
                .kendoDatePicker({});
    }
 
    $(function () {
        // Client side kendo data source passed to kendo grid. Uses AllSamplesController for CRUD operations.
        var sampleGridDataSource = new kendo.data.DataSource({
            batch: true,
            pageSize: 20,
            schema: {
                model: {
                    id: "Id",
                    fields: {
                        Id: { type: "number", editable: false },
                        TestItem: { defaultValue: { Code: "001", System: "none"} },
                        TestDate: { type: "datetime" },
                    }
                }
            },
            transport: {
                read: {
                    url: actions.common.rootUrl + "api/Allsamples/?anlagenId=" + amplify.store("SelectedItemId"),
                    type: "Get"
                },
                create: {
                    url: actions.common.rootUrl + "api/Allsamples/?anlagenId=" + amplify.store("SelectedItemId"),
                    type: "PUT",
                    contentType: 'application/json;charset=utf-8'
                },
                update: {
                    url: actions.common.rootUrl + "api/Allsamples/?anlagenId=" + amplify.store("SelectedItemId"),
                    type: "PUT",
                    contentType: 'application/json;charset=utf-8'
                },
                destroy: {
                    url: actions.common.rootUrl + "api/Allsamples",
                    type: "DELETE",
                    contentType: 'application/json;charset=utf-8'
                },
                parameterMap: function(data, operation) {
                    if (operation != "read") {
                        return kendo.stringify(data.models);
                    }
                }
            },
            requestEnd: function(e) {
                if (e.type == "create") {
                    this.read();
                }
            },
            change: function(e) {
                //if (e.action == "itemchange" || e.action == "add" || e.action == "remove")
                if (e.action == "itemchange")
                {
                    window.sampleViewModel.setIsDirty(true);
                }
            }
        });
 
        var sampleGrid = $("#sample-grid").kendoGrid({
            dataSource: sampleGridDataSource,
            scrollable: true,
            navigatable: true,
            sortable: true,
            columnMenu: true,
            selectable: "row",
            editable: {
                confirmation: "Delete the selected record?",
            },
            pageable: {
                pageSizes: [10, 20, 50],
                refresh: true,
            },
            filterable: true,
            resizable: true,
            height: 500,
            columns: [
                {
                    field: "TestItem",
                    title: "TestItem",
                    width: "120px",
                    editor: ItemDropDownEditor,
                    template: "#=Items.System#",
                },
                 {
                    field: "TestDate",
                    title: "TestDate",
                    width: "100px",
                    type: "date",
                    format: "{0:dd.MM.yyyy}",
                    editor: TestdateEditor,
                    filterable: {
                        ui: "datepicker"
                    }
                },
            ]
        }).data().kendoGrid;
 
        sampleGridDataSource.bind('dataBound', function(e) {
            this.element.find('tbody tr:first').addClass('k-state-selected');
        });
 
 
        var jsonModel = @Html.Raw(Json.Encode(Model));
 
        var sampleViewModel = new sampleViewModel(jsonModel, sampleGrid);
 
        kendo.bind($("body"), sampleViewModel);
 
    });
    </script>
}

 

Does anybody have an idea what causes the offset of one day?

 

Best regards

Manu

Manu
Top achievements
Rank 1
 answered on 27 Jun 2016
1 answer
136 views

Hello,

I'm looking to add a embedded link column to a kendo grid for a networked file or folder.  (ex:123Fake.txt has an embedded hyperlink of  \\Server1\Folder1\123Fake.txt )

The server that will run the site is in the same network as Server1 so I don't see security as a problem.  After a day of trying to setup a example and getting nowhere I need a hand with how to do this properly.  If it isn't possible then confirmation it's not possible will work too.

 

thanks

Ianko
Telerik team
 answered on 27 Jun 2016
4 answers
568 views
I wanted to know if there is a way to leverage the
directory browser used as part of the editor widget as a stand-alone feature to
use as a file manager through the UI. I’d like to use it to access a directory
(and series of subfolders) as part of an application that I’m building for
administrative access to files uploaded by users to be used as templates for a
service.
Dimo
Telerik team
 answered on 27 Jun 2016
1 answer
126 views

Hello!

Could you please provide a sample project similar to this one, but with a foreign key column? I was trying to implement this on my own, but wasn't successful.

http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/how-to/grid-bind-to-datatable

 

Best regards,

Kaan

Viktor Tachev
Telerik team
 answered on 27 Jun 2016
1 answer
248 views

Hi!

I have an editor template (DATETIMEEDIT.cshtml) for date times, which I use in a Grid and also in an ordinary form:

@model DateTime?
@(Html.Kendo().DateTimePickerFor(m => m)
.TimeFormat("HH:mm")
.HtmlAttributes(new { style = "width:100%;" })
)

 

The editor is bound to the Grid in this way:

var c = columns.Bound(fieldName);
c.EditorTemplateName("DATETIMEEDIT");
c.Format("{0:dd.MM.yyyy HH:mm}");

 

And this is how the editor is integrated into the HTML form:

@Html.EditorFor(v => dateTime, "DATETIMEEDIT", fieldName)

 

When I update the date and time, the Grid sends it back to the server as "3/21/2016 5:35:00 PM", and the form as "21.03.2016 17:35".

However, I need a reliable DateTime exchange format between the server and the client. "dd.MM.yyyy HH:mm" (24 hour) would be ok, but any other consistant solution would be alright too because if the server receives an unpredictable format, then I can't convert it into a C# DateTime object. Maybe there is another preferrable way to handle date times between the client and server? I don't even know why the Grid uses the American format as default because I work on a German workstation here.

 

Best,

Kaan

 

 

Viktor Tachev
Telerik team
 answered on 27 Jun 2016
4 answers
185 views

I have noticed many glaring omissions and incomplete documentation when trying to look up how to use some of these components.  For example, for the MVC Grid documentation found at http://demos.telerik.com/aspnet-mvc/grid/remote-data-binding it shows in the cshtml code:

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()   
    .Name("grid")
    .Columns(columns => {
        columns.Bound(p => p.OrderID).Filterable(false);
        columns.Bound(p => p.Freight);
        columns.Bound(p => p.OrderDate).Format("{0:MM/dd/yyyy}");
        columns.Bound(p => p.ShipName);
        columns.Bound(p => p.ShipCity);
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .HtmlAttributes(new { style = "height:550px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("Orders_Read", "Grid"))
     )
)

Notice the Read method on the DataSource method, pointing to a GET Action called "Orders_Read" in the "Grid" controller.  Of course looking at the controller code example only shows:

using System.Web.Mvc;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
 
namespace Kendo.Mvc.Examples.Controllers
{
    public partial class GridController : Controller
    {
        public ActionResult Remote_Data_Binding()
        {
            return View();
        }
    }
}

No Orders_Read action there, and no clue as to what other actions the DataSource object can make use of in this Grid context.  I assume the user is supposed to go look up the DataSource component now, which may or may not have an HtmlHelper.  I've noticed that about a few other components...  needing to do something, trying to find hhelp and it takes one to the Kendo UI documentation, where the syntax and building of these components is vastly different than the HTML Helpers of the MVC libraries.

 

So what is the best way to actually learn how to use these components? I'm looking for all levels of help, basic, intermediary, and advanced.  Like using an MVC Grid and the MVVM model together from C# ASP.NET...

 

 

Misho
Telerik team
 answered on 27 Jun 2016
3 answers
318 views

We have an Issue with the Server-side filtering feature from the kendoAutoComplete. This autocomplete is contained in a html form tag. When the request is performed on the asp.net mvc endpoint the DataSourceRequest is completly empty, becuase all the values for this object are in HttpContext.Request.Form, from where the DataSourceRequestAttribute doesn't parse it from. What should we do, to get the DataSourceRequest correctly bound?

HTML Code

<form class="navbar-form" role="search" method="post" action="@Url.Action("Results","Search")">

// some other controls

<div class="input-group">
<span class="k-widget k-autocomplete k-header k-state-default myClass">
<input type="text" id="autoCompleteSearch" name="autoCompleteSearch" class="form-control" />

</span>
<div class="input-group-btn">
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
</div>
</div>
</form>

 

JS Code:

$('#autoCompleteSearch').kendoAutoComplete({
minLength: 1,
dataTextField: 'Caption',
dataValueField: 'Value',
filter: "contains",
dataSource: {
serverFiltering: true,
transport: {
read: {
type: "post",
dataType: "json",
url: '@Url.Action("AdvancedSearchAutoComplete_Read", "AjaxValues")?searchType=' + window.searchType
}
},
schema: {
data: "Data"
}
}
});

Server-side:

[System.Web.Mvc.HttpPost]
public JsonResult AdvancesSearchAutoComplete_Read(int searchType, [DataSourceRequest] DataSourceRequest request)
{

//...

}

 

Thank you in advance!

Peter Milchev
Telerik team
 answered on 24 Jun 2016
1 answer
2.3K+ views

Hello,

is it possible to remove the title and the Update and Cancel button so that I can use my own template?
(if yes how to call the upade and cancel with javascript)

I want to have my own Toolbar with update and cancel and some other bottons and also e special title bar...

robert

Maria Ilieva
Telerik team
 answered on 24 Jun 2016
5 answers
792 views

Hello,

I am a beginner with kendo UI and have a problem with the following input box:

<input data-role="datepicker" data-format="dd.MM.yyyy" data-bind="enabled: isEnabled, value: DateToSave" />

The date is picked correctly (displayed on the page), but after saving to the server the value in the server table is one day off. The displayed value on the page (after saving) is also one day off from the picked value.

These are the project infos:

- Telerik ASP.NET MVC 4 (v2013.3.1119)

- culture: "de-AT"

editorTemplate and DateTimeModelBinder

@model DateTime?
 
<div class="span-datepricker">
    <input name="datepicker" />
</div>
 
<script>
    $(document).ready(function () {
        // create DatePicker from input HTML element
        $("input[name='datepicker']").kendoDatePicker();
    });
</script>

using System;
using System.Globalization;
using System.Web.Mvc;
 
namespace Presentation.Host.App_Start
{
    public class DateTimeModelBinder : IModelBinder
    {
        private const string DateTimePattern = "ddd MMM dd yyyy HH:mm:ss 'GMT'zzz";
 
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            string value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName).AttemptedValue;
            if (!string.IsNullOrWhiteSpace(value))
            {
                int timeZoneInfoIndex = value.IndexOf(" (", StringComparison.Ordinal);
                if (timeZoneInfoIndex > 0)
                {
                    value = value.Substring(0, timeZoneInfoIndex);
                    return DateTime.ParseExact(value, DateTimePattern, CultureInfo.InvariantCulture).AddDays(1);
                }
 
                return DateTime.Parse(value);
            }
            return null;
        }
    }
}

ViewModel:

.....
public DateTime? DateToSave { get; set; }
...

If you could give me some hints where to start looking I'd be thankful.

Best regards.

Manu

Maria Ilieva
Telerik team
 answered on 24 Jun 2016
6 answers
2.4K+ views

Hello,

I have the following grid with a deleteRow event where I want to use my own conformation (sweetalert). In the event I first cancel the delete operation and then ask the user if he will delete the row or not.

Which code is necessary to delete the current row with Javascript/jQuery (line 19. in the code)?

01.function deleteRow(e) {
02. 
03.       $("#grid").data("kendoGrid").cancelChanges();
04. 
05.       swal({
06.           title: "Löschen",
07.           text: "Sind Sie sich sicher, dass Sie den aktuellen Datensatz löschen wollen?",
08.           type: "warning",
09.           showCancelButton: true,
10.           confirmButtonColor: "#DD6B55",
11.           confirmButtonText: "OK",
12.           cancelButtonText: "Abbrechen",
13.           closeOnConfirm: true,
14.           closeOnCancel: true
15.       },
16.           function (isConfirm) {
17.               if (isConfirm) {
18.                   
19. 
20. 
21.               }                  
22.           });
23.   }

Kostadin
Telerik team
 answered on 24 Jun 2016
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
Upload
ComboBox
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
ListView (Mobile)
Pager
Accessibility
ColorPicker
DateRangePicker
Wizard
Security
Styling
Chat
MediaPlayer
TileLayout
DateInput
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
+? more
Top users last month
Top achievements
Rank 1
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ivory
Top achievements
Rank 1
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
YF
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Top achievements
Rank 1
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
ivory
Top achievements
Rank 1
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
YF
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?