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

[Solved] timespans in edit templates

10 Answers 220 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.
Michael
Top achievements
Rank 1
Michael asked on 17 Apr 2011, 12:25 AM

OK i built my fancy modelbinder according to this post/question:

Generic TimeSpan binding in Asp.NET MVC 2

but now the timespan isnt being displayed when the same template is being called for edit?

I mean the value isnt being passed to the textbox.

        <div class="editor-label">
        @Html.LabelFor(model => model.strHandicap)
   
</div>
   
<div class="editor-field">
        @Html.EditorFor(model => model.strHandicap)
        @Html.ValidationMessageFor(model => model.strHandicap)
   
</div>

displays 00:00:00 even though the value is shown in the grid prior to editing?

atm ive got around it by displaying it as a string & parsing the string upon submitting the edit, but its broke my model binder and all that goodness is gone... 8(

what am i missing??

10 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 18 Apr 2011, 07:46 AM
Hello Michael,

 Are you using Ajax editing? If yes then perhaps the reason it does not work is the way time spans are serialized to JSON (because there is no corresponding type in JavaScript):

{
"Ticks":600000000,
"Days":0,
"Hours":0,
"Milliseconds":0,
"Minutes":1,
"Seconds":0,
"TotalDays":0.00069444444444444436,
"TotalHours":0.016666666666666666,
"TotalMilliseconds":60000,
"TotalMinutes":1,
"TotalSeconds":60
}
The grid is not aware that this is a timespan and expects a single value (such as "10:00:00") to be rendered instead. I can suggest you to handle the OnEdit and OnSave events of the grid and do the proper parsing there.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 18 Apr 2011, 12:59 PM
think ill leave my string work around as i cant seem to understand javascript AT ALL!

i am still abttling with the onedit function to hide a fields in the edit/insert templates.

Just how do i reference the fields i want? and is there a means to hide both the labelfor & editorfor fields?

0
Atanas Korchev
Telerik team
answered on 18 Apr 2011, 01:20 PM
Hi Michael, 

In order to hide a DOM element you need a way to identify it first. Fortunately jQuery makes that easy. You can use a selector to find the right element and then the hide method. Here is a quick example which will hide the "Name" field of a hypothetical object which has a "Name" property:

function onEdit(e) {
    $(e.form) // "form" is the FORM element which contains the editor elements
      .find("#Name")     // find all elements with "id" set to "Name" - in this case this would be a textbox
      .hide();    //hide those elements
}     

There are other (server-side) ways to hide a field from the editor form:
  1. Decorate the property with [ScaffoldColumn(false)].
  2. Decorate the property with [HiddenInput(DisplayValue = false)]

I hope this helps, Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 18 Apr 2011, 02:37 PM
thanks!!

so i need to determine the name of the field from "labelfor" and editorfor..guess its a convention but ill go look at the source!!

I think i need to do this in java as i want them displayed in edit but not in add from the template?
0
Michael
Top achievements
Rank 1
answered on 18 Apr 2011, 02:57 PM
ok heres the source html

<input id="GroupID-input"

and on my edittemplate partialview i have this at the end

<script type="text/javascript">
    function Grid_onEdit(e) {      
  
        var mode = e.mode;
        
        if (mode == 'insert') {
            //donot show
            $(form)
                .find('#GroupID-input')
                .hide();
             
        }
    }
</script>

wrong??
0
Atanas Korchev
Telerik team
answered on 18 Apr 2011, 03:32 PM
Hi Michael,

 You should define this as event handler of the OnEdit client-side event of grid. The script tag must be defined in the view where the grid is defined.

All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 18 Apr 2011, 11:27 PM

                          
.ClientEvents(events => events.OnEdit("Grid_onEdit"))
                           .Groupable()
                           .Editable(editing => editing.Mode(GridEditMode.PopUp))
)
 
<script type="text/javascript">
    function Grid_onEdit(e) {
 
        var mode = e.mode;
 
 
        if (mode == 'insert') {
            //donot show
            $(form)
                .find("#GroupID-input")
                .hide();
 
        }
 
    }
</script>


this is the tail of my grid...with the onedit command, but it still fails to fire the javascript (in firebug)
0
Atanas Korchev
Telerik team
answered on 19 Apr 2011, 07:08 AM
Hi Michael,

 I am not sure what is wrong at your end. The configuration looks ok. Could it be that you are not using ajax editing? The OnEdit event will fire only for ajax editing.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 20 Apr 2011, 03:38 AM
negative Houston:

                           .DataBinding(dataBinding => dataBinding.Ajax()
                               .Select("_ResultsForEditing", "handicapper")
                               .Insert("Insert", "Handicapper")
                               .Update("_SaveAjax", "Handicapper"))
                           .Pageable(paging => paging.PageSize(40))
                           .Scrollable(scrollable => scrollable.Height("300px"))
                           .Filterable(filter =>filter.Enabled(true))
                           .Sortable(config => config
                               .OrderBy(order => order
                                   .Add(((string)ViewData["view"]) == "sortedByDate" ? "ActualTimeString" :
                                       "FullName")
                               )
                           )
                           .ClientEvents(events => events.OnEdit("Grid_onEdit"))
                           .Groupable()
                           .Editable(editing => editing.Mode(GridEditMode.PopUp))
)
0
Atanas Korchev
Telerik team
answered on 20 Apr 2011, 07:24 AM
Hello Michael,

 Well in that case I am not sure how to proceed. The OnEdit event is supposed to fire during editing (you can check our client-events example). Perhaps you can attach a working solution which we can test with.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Michael
Top achievements
Rank 1
Share this question
or