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

[Solved] combo box in grid

1 Answer 107 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.
Ofer
Top achievements
Rank 1
Ofer asked on 19 Mar 2012, 01:37 PM
hello  i have a problem when i try to implement combo box in grid. i have grid with 4 filed. on of them is combo box and when i click in this filed it not fire the event  OnEdit. the other filds fire the event.

what i do is :

in class model :
         public long filed1 { getset; }
        public decimal? filed2 { getset; }
        public decimal? filed3 { getset; }
 
        [UIHint("DDLAsmahtaType"), Required]
        public EditAsmahtaType filed3 { getset; }

in DDLAsmahtaType :

@(Html.Telerik().ComboBox()
      .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
              .DataBinding(binding => binding.Ajax().Select("_SelectAsmahtaType""Tik")))


in SelectAsmahtaType in the control Tik :

 
 
        [HttpPost]
        public ActionResult _SelectAsmahtaType()
        {
 
            List<SelectListItem> ListData = new List<SelectListItem>();
            ListData.Add(new SelectListItem() { Selected = true, Text = "Choose1", Value = "0" });
            ListData.Add(new SelectListItem() { Selected = false, Text = "Choose2", Value = "1" });
 
            return new JsonResult { Data = new SelectList(ListData.ToList(), "Value""Text") };
        }


and the grid :

@(Html.Telerik().Grid<LawyerAccountDTL>( )
        .Name("Grid")
        .DataKeys(keys =>
        {
            keys.Add(o => o.AccountId);
        })
        .ToolBar(commands =>
        {
            commands.Insert();
            commands.SubmitChanges();
        })
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
                .Select("InsertTakbulimAjax""Tik")
                .Update("_SaveBatchEditing""Tik");
        })
            .Columns(Cols =>
        {
 
                                        Cols.Bound(Col => Col.Filed1)
                                        .Format("{0:g}")
                                            .HeaderHtmlAttributes(new { @style = "background-color: #d5e4ff; border-right: 1px solid #88aafb; border-bottom: 1px solid #88aafb; font-style:arial; font-size:12px; font-weight:bold; height: 20px;" })
                                        .HtmlAttributes(new { @id = "Grid_Row" })
                                        .Title("1 ")
                                        .Sortable(true)
                                        .Width("14%");
                                        Cols.Bound(Col => Col.Filed2)
                                        .Format("{0:g}")
                                            .HeaderHtmlAttributes(new { @style = "background-color: #d5e4ff; border-right: 1px solid #88aafb; border-bottom: 1px solid #88aafb; font-style:arial; font-size:12px; font-weight:bold; height: 20px;" })
                                        .HtmlAttributes(new { @id = "Grid_Row" })
                                        .Title("1 ")
                                        .Sortable(true)
                                        .Width("14%");
                                                    Cols.Bound(Col => Col.Filed3)
                                        .Format("{0:g}")
                                            .HeaderHtmlAttributes(new { @style = "background-color: #d5e4ff; border-right: 1px solid #88aafb; border-bottom: 1px solid #88aafb; font-style:arial; font-size:12px; font-weight:bold; height: 20px;" })
                                        .HtmlAttributes(new { @id = "Grid_Row" })
                                        .Title("1 ")
                                        .Sortable(true)
                                        .Width("14%");
                                Cols.Bound(Col => Col.DDLAsmahtaType)
                                    .ClientTemplate("<#= DDLAsmahtaType.AsmahtaName #>").Width(230)
                                        .HeaderHtmlAttributes(new { @style = "background-color: #d5e4ff; border-right: 1px solid #88aafb; border-bottom: 1px solid #88aafb; font-style:arial; font-size:12px; font-weight:bold; height: 20px;" })
                                        .Sortable(false)
                                   .HtmlAttributes(new { @id = "Grid_Row" })
                                        .ReadOnly()
                                        .Title("סוג אסמכתא ")
                                        .Width("23%");
                              
 
        })
            .ClientEvents(events => events.OnDataBinding("Grid_onDataBinding").OnEdit("Grid_OnEdit").OnSave("Grid_OnSave"))
            .Editable(editing => editing.Mode(GridEditMode.InCell))
            .Pageable()
    )




<script type="text/javascript">
    function Grid_onDataBinding(e) {
        alert('1');
            var grid = $(this).data('tGrid');
            if (grid.hasChanges()) {
                if (!confirm('You are going to lose any unsaved changes. Are you sure?')) {
                    e.preventDefault();
                }
            }
        }
 
        function Grid_OnEdit(e) {
            alert('2');
           
            var $combo = $(e.cell).find('#Employee');
            if ($combo.length > 0) {
                var combo = $combo.data('tComboBox');
                combo.fill(function () {
                    combo.value(e.dataItem['Employee'].EmployeeID)
                });
            }
        }
 
        function Grid_OnSave(e) {
            alert('ddsssssddd');
            var $combo = $(e.cell).find('#Employee');
            if ($combo.length > 0) {
                var combo = $combo.data("tComboBox"),
                    selectItem = combo.selectedIndex > -1 ? combo.data[combo.selectedIndex] : null;
 
                if (selectItem) {
                    var splitName = selectItem.Text.split(" ");
                    e.values["Employee"] = { EmployeeID: selectItem.Value || selectItem.Text, FirstName: splitName[0], LastName: splitName[1] };
                } else {
                    var value = combo.value();
                    e.values["Employee"] = { EmployeeID: value, FirstName: value, LastName: value };
                }
            }
        }
</script>


thanks for help.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Mar 2012, 12:07 PM
Hello Ofer,

For which property are you setting the ComboBox editor template? At least, in the provided code snippet you have two properties with the "filed3" name. If the editor template is declared for the "DDLAsmahtaType" field, the OnEdit event won't be triggered as the column is set as ReadOnly and it won't enter edit mode.

All the best,
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.
Tags
Grid
Asked by
Ofer
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or