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

[Solved] Need to make readonly field editable while inserting new row

4 Answers 227 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.
vijayakumar
Top achievements
Rank 1
vijayakumar asked on 20 Jul 2011, 06:37 AM

We are using Telerik MVC grid with “InLine” editing mode (GridEditMode.InLine) with version 2011.2.712 .
In this, we have requirement to make one of the columns in the grid as “read only” while editing the existing rows (the rows which are bound from db fetch).
 i.e.., This column should be “read only” only during editing the existing row,  and it should become editable while inserting the new row.

Note: Grid column has a method “ReadOnly()” , but it makes the column read-only all the time (while editing the existing row as well as inserting the new row).
Also tried with setting the attribute “ScaffoldColumn”, but it behaved same way.
Is there anyway to achieve this?

4 Answers, 1 is accepted

Sort by
0
Igniter
Top achievements
Rank 1
answered on 11 Aug 2011, 07:25 AM
I have the same issue. Please let me know if you have found solution. TIA

UPDATED:
For now such workaround works:

1. Add OnEdit event on your grid add
.ClientEvents(events => events.OnEdit("Grid_onEdit")

2. And add handler script

<script type="text/javascript">
        function Grid_onEdit(e) {
            if (e.mode == "edit") {
                var myNotEditableField= $(e.form.MyNotEditableField);
                var value = myNotEditableField.val();
                var $newInput = $('<input type="hidden" name="MyNotEditableField" id="MyNotEditableField" value="" />' + '<span>' + value + '</span>').val(value);             
                myNotEditableField.replaceWith($newInput);
               //or just myNotEditableField.replaceWith(value); depends on your conroller
            }
        }
</script>
0
vijayakumar
Top achievements
Rank 1
answered on 12 Aug 2011, 12:21 PM

Great.. This is very nice work-around... Thanks a lot.
In our case, it is dropdown field which we need to replace. so used below code. it worked fine.

 

if (e.mode == "edit") {
            var $countryInputField = $(e.form.Country);
            var selectedCountryVal = $countryInputField.val();
            var $countryDropdown = $countryInputField.closest('.t-dropdown');
            var $newInput = $('<input type="hidden" name="Country" id="Country" value="" />' + '<span>' + selectedCountryVal + '</span>').val(selectedCountryVal);
            $countryDropdown.closest('td').prepend($newInput);
            $countryDropdown.remove();
        }

 

 

 

 

 

0
Donna Stewart
Top achievements
Rank 1
answered on 02 Sep 2011, 05:23 PM
Thank you!  This is the very thing I posted a question on yesterday and was told it was not possible!  Maybe we should request this functionality be added?

Thanks again!
0
Peter
Top achievements
Rank 1
answered on 12 Jan 2012, 06:58 AM
Thanks for this solution.

Is there anywhere we can make a suggestion to Telerik to improve the functionality in this area?
Tags
Grid
Asked by
vijayakumar
Top achievements
Rank 1
Answers by
Igniter
Top achievements
Rank 1
vijayakumar
Top achievements
Rank 1
Donna Stewart
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Share this question
or