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

[Solved] Client Side editing

9 Answers 151 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.
Marco
Top achievements
Rank 1
Marco asked on 25 Mar 2010, 11:39 AM
hello i'm trying to call a js function on edit button.

this is the code
    $(function() {  
        $('.t-grid-edit').click(function(){ 
            alert("test"); 
        }); 
    }) 

i want to create a custom dropdown for one of my columns because the items of dropdown will depend on the primary key of row. and i think i can't achieve such behavior using editorTemplates. i'm correct? can someone recommend me the better approach to accomplish this task?

Best Regards

Marco

9 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 25 Mar 2010, 03:23 PM
Hi Marco,

The recommended approach is to use editor templates. Any JavaScript code you have defined in the ascx will get executed so you can create whatever UI is required.

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
Marco
Top achievements
Rank 1
answered on 29 Mar 2010, 12:35 PM
hello.

just one more think. 
how can i preserve the state of control on editor template when using ajax binding?
i have 
<%= Html.DropDownList(null, new SelectList(ServiceLocator.Current.GetInstance<ILoggedOnUser>().AvailableUnities, "id", "nome", Model.id))%>

in server side binding we can use viewmodel but in ajax the model is always null.

Best Regards
Marco

0
Atanas Korchev
Telerik team
answered on 29 Mar 2010, 01:12 PM
Hello Marco,

I am not sure I understand your requirements. What do you mean by preserving the state of the control? Please elaborate.

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
Marco
Top achievements
Rank 1
answered on 29 Mar 2010, 01:49 PM
hello atanas.

i have a column that shows a dto property containing the description, but when i pass to edit mode the selected value is the first and not the same as on read mode.
for example: image a dto property that shows employee name on read mode, and than on edit mode shows a drop down list whit all possible employees but the default value should be the same as on read mode, and in this case is the first of list.

so how can i make the selected value on edit equals to the employee on read mode?

i was trying to use the model but the model is always null.

Best Regards
Marco 
0
Atanas Korchev
Telerik team
answered on 29 Mar 2010, 02:29 PM
Hello Marco,

You should use JavaScript to set the selected value of the dropdown list. You can try something like this:

<script type="text/javascript">
    var name = '<%= ViewData.TemplateInfo.HtmlFieldPrefix %>'; // The name of the bound field
    var $input = $(':input[name=' + name + ']'); //get the HTML element in the editor
    var grid = $('#Grid').data('tGrid'); //the grid client object
    var dataItem = grid.dataItem($input.closest('tr')); //retrieve the data item to which the row is bound to

    alert(dataItem[name]); //use the dataItem to retrieve any value from it
    $input.val(dataItem.id); //set the value of the HTML element
</script>

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
Marco
Top achievements
Rank 1
answered on 30 Mar 2010, 12:25 PM
hello Atanas i have tried your suggestion but  the input tag don't exist on any phase.

on read i just have a <td>Some value</td> and after that i will have a span validation field that enables me to get the column that i want update.

but than i need to get the text that exist previously in my td, call some server side method to get me all possible values to insert in drop down and make a string compare to identify what should be the value that i need to mark as selected.

does't exist a better and simple way to do this? 

Best Regards

Marco Teodoro 
0
Atanas Korchev
Telerik team
answered on 30 Mar 2010, 12:43 PM
Hi Marco,

The code I have pasted must be added to the EditorTemplate ASCX. The input tag will exist there (if you are using an input tag that is).

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
Marco
Top achievements
Rank 1
answered on 30 Mar 2010, 12:49 PM
i think i found  the better way to do this.

columns.Bound(o => o.someID).ClientTemplate("<#=RelatedObject.Description#>")

but this way i will need to have the related object instantiated or i will get a RelatedObject is null error.

this way it works. is this a good way, or will i have some performance problems?

thanks for you support Atanas.

Best Regards

Marco 
0
Atanas Korchev
Telerik team
answered on 30 Mar 2010, 12:54 PM
Hi Marco,

I am not really sure what RelatedObject.Description is. In the prior example I am showing how to get the JavaScript object which represents the data item for the current row. I am also showing how to get using jQuery any input controls (textbox, checkbox, select) and set its value to some property of the data item object.

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
Marco
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Marco
Top achievements
Rank 1
Share this question
or