This is a migrated thread and some comments may be shown as answers.

Showing the Date Picker in the Inline Edit Template

9 Answers 298 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Reid
Top achievements
Rank 2
Reid asked on 23 Jan 2012, 02:50 PM
Hi All,

In the demo here (Editing Ajax Demo) the inline row being edited shows the Date Time Picker.  I cannot figure out how that happens?  I am looking through the source code in the examples which also shows it at runtime, but I cannot see any reference to it in the markup. 

It looks like the ClientTemplate() is available and should be used but the demo does not show it for anything other than the "Discontinued" checkbox.

Any help would be appreciated here.

Also, it is possible to put a partial view (maybe Razor) inside the template for a given column?  I suspect that would have to be bound to the model, so I am not sure how to do that, just curious.

Thanks,

Reid

9 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 25 Jan 2012, 02:32 PM
Hello Reid,

The DateTimePicker is the default editor template for properties of type DateTime. You don't have to do anything to specify this. You could change it by defining a custom editor template. More information and examples regarding this is available in the Client Edit Templates demo and Display and Editor Templates section of the Grid's documentation.
Using a partial view for a column's template is possible when using Server Binding. You should just set it in the column's Template method. For example:
.Columns(columns =>
{
    columns.Template(@<text>
        @Html.Partial("PartialViewName", item.PropertyName)
    </text>);
})
When using Ajax Binding you should use the ClientTemplate method and access the data by using the "<#= PropertyName #>"  expression. It is possible to set in the ClientTemplate a partial view as string but I wouldn't recommend it.

Greetings,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Reid
Top achievements
Rank 2
answered on 25 Jan 2012, 05:35 PM
Hi Daniel,

Thank for replying.

You mention that I should not need to do anything for the DateTimePicker to show.  Not sure why as default it would not then.
Here is the field in the Model (contained in the ViewModel)

[Required]
[DisplayName("Start Date")]
[DataType(DataType.DateTime)]
public DateTime? FilterStartDate { get; set; } 

The field needs to be nullable but for experimentation sake I changed and the problem remains.  I don't want to have to define a custom template I would like to figure out why the default is not showing a DateTime picker.  Whether nullable of not, it shows as a standard text box.

I originally started oout doing the server side and could not get it working right so I started again doing the client ajax editing model.  In both the client and server binding there is the (Editor) part that drops in the user control.  Do I need to do that for the DateTime Editor?

The example here :http://demos.telerik.com/aspnet-mvc/grid/editingajax is what I am modeling because I need to insert and edit in the grid. And in that demo there is a client template ued for the Checkbox section, nothing for the date time column.  There is though the Date.ascx portion and I think that is key but I see no other reference to it.

Thanks,

Reid

0
Daniel
Telerik team
answered on 26 Jan 2012, 11:47 AM
Hello Reid,

I apologize. There is one requirement. You should add the default Editor Templates. They are included automatically in the project if you use the Telerik project template or you could add them manually. They can be found in a subfolder of the Telerik install folder by EditorTemplates or EditorTemplates-Razor depending on the View Engine.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Reid
Top achievements
Rank 2
answered on 26 Jan 2012, 05:53 PM
Daniel,

I replicated the folder you mention in the examples solution and added the Telerik namespaces to the User Controls. 

Shared ->EditorTemplates

That made no difference.  I tried copying the User Control files into the same folder as the view, the Shared folder and the site root and  the result is the same.  No DateTimePicker controls are showing up in the two DateTime? columns.

Also below you say, "When using Ajax Binding you should use the ClientTemplate method and access the data by using the "<#= PropertyName #>"  expression".  I am accessing the data through the HTTP posts in the controller with the model intact.  I am not sure what you mean by that.

Is there something else that needs to be done.

Thank again for the support,

Reid
0
Reid
Top achievements
Rank 2
answered on 26 Jan 2012, 06:15 PM
Daniel,

I think my issue is that I had the Tempate code commented out.  But I still cannot get the page to load the template section for those two columns without errors.  Here is the error:

" Keyword, identifier, or string expected after verbatim specifier: @"

columns.Bound(eg => eg.FilterStartDate).Width(100).Title("Start Date").Format("{0:d}")
.Template(@<text>Html.Partial("Date.ascx", "FilterStartDate")</text>);   
                                                    
columns.Bound(eg => eg.FilterEndDate).Width(100).Title("End Date").Format("{0:d}")
.Template(@<text> Html.Partial("Date.ascx","FilterEndDate")</text>); 

One of the methods in the Partial's overloads takes the model.  Should I be using specifying the fieldname as above as a string in quotes or point to the model.  If the latter I am note sure how to point to the specific record as the datasource is a List<> of the objects.

Thanks again,

Reid

0
Daniel
Telerik team
answered on 30 Jan 2012, 11:26 AM
Hello Reid,

The error you are getting is because you are missing the "@" character before the Html helper method. Also, when using the HTML Partial helper, you should omit the file extension. To pass the value to the Partial view you should use the Razor's item parameter. For example:
columns.Bound(eg => eg.FilterStartDate)
    .Template(@<text>@Html.Partial("Date", item.FilterStartDate)</text>);
However, this is not the proper way to use the DatePicker when editing. The Template and ClientTemplate methods are used to customize how the data is visualized rather than how it is edited. I suspect that the DatePicker editor template isn't applied because you have copied the files with the ascx file extension. If you are using the Razor View Engine you should copy the files from the EditorTemplates-Razor folder with cshtml extension.

Kind regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Reid
Top achievements
Rank 2
answered on 31 Jan 2012, 01:52 PM
Daniel,

I do have a few Razor views in the solution which is not a razor solution primarily, but I did as the demos did, added the control as an .ascx. 

I have not been able to focus back on this view for over a week (those pesky managers ..) but hopefully will resolve it with your last post.

Thanks,

Reid

0
Chillax
Top achievements
Rank 1
answered on 20 Jul 2012, 08:12 AM
0
Reid
Top achievements
Rank 2
answered on 20 Jul 2012, 12:31 PM
Hello Chillax,
Thank you very much for those links.

Reid
Tags
Grid
Asked by
Reid
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Reid
Top achievements
Rank 2
Chillax
Top achievements
Rank 1
Share this question
or