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

dropdownlist in grid on batch edit

2 Answers 89 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.
javier
Top achievements
Rank 1
javier asked on 05 Jun 2012, 06:24 AM
Hello,
I have a grid ajax binded in batch edit mode. In my model I have an integer field which is not a foreign key, it's just an integer to represent one of three status. I did a editor template with a dropdownlist and I populated with three items statically (1-Status 1, 2- Status 2 and 3- Status 3). I also decorated the integer field of my model with a UIHint with the same name that the editor template.
Finally, I added this code to handle the on edit event of the row and to match the the integer Id with the value field of the dropdownlist:

        function onEdit(e) {
            $(e.form).find('#drowndownId).data('tDropDownList').select(
            function (dataItem) {
                if (dataItem.Value == e.dataItem['objectIntegerField']) {

                    return true;
                }
                else
                    return false;
            });
        }


The problem #1 is that during "no edition mode", the integer number is shown in the column and when I clicked on it the onEdit field is fired and the corresponding Id in the dropdownlist is selected and here comes the #2 problem: when the row exits the edition mode the dropdownlist dissapears and the integer field appears again.

The probem #1 was easy to solve, I changed the plain integer field with an object field containing the Value and the Text and I added a client template like this:                    
     columns.Bound(c => c.ObjectField)
                             .ClientTemplate("<#= ObjectField.Text #>")

Now I solved the first problem, so I can see the Texts in the column's Grid and when clicking on to edit the dropdownlist sucessfully choses the corresponding item but the problem #2 still exists, so after changing the item selection in the list and clicking in other row (I mean, after exiting edition mode) the same colum Text appears again and the dropdownlist selection is gone.

I have spent 3 days with this, so I have tried many forum answers with no results, I have downloaded sample code but most of the samples matches string fields with dropdownlists or foreign integer fields with another table. 

Thank you in advance,

2 Answers, 1 is accepted

Sort by
0
javier
Top achievements
Rank 1
answered on 05 Jun 2012, 05:29 PM
I finally solved by handling this event:

Grid_OnSave


Thank you,
0
Tarun
Top achievements
Rank 1
answered on 28 Sep 2012, 07:21 AM
I can help you.
Can you attach the zip file containing your view, controller etc. code?
Tags
Grid
Asked by
javier
Top achievements
Rank 1
Answers by
javier
Top achievements
Rank 1
Tarun
Top achievements
Rank 1
Share this question
or