<script type="text/javascript"> var Data = [ { OrderID: '10248', CustomerID: 'VINET', EmployeeID:'1', Employee:{Address:'India'},Freight:'33.38',ShipName:'Alfreds Futterkiste',ShipCountry:'Brazil'}, ------------------- ]; var data = ej.DataManager(Data).executeLocal(ej.Query().select("EmployeeID")); $(function () { $("#Grid").ejGrid({ dataSource: Data, allowPaging: true, editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, editMode: "batch" }, columns: [ ------------------ ], cellEdit: function(e){ if(e.columnName == "EmployeeID" && !(e.value == "")) setTimeout(function (e) { if($('.e-ejinputtext').val() != "") $('.e-ejinputtext').ejDropDownList({dataSource:data,value:$('.e-ejinputtext').val()}); //Change the input text box into ejDropDownList when cell has value }, 2); } }); }); </script> |
Hi Luis,
Thanks for contacting Syncfusion support.
We have analyzed your query and we suspect that you want render the dropdownlist when the cell has value, otherwise it will maintain as string edit. We have achieved the same using the cellEdit event of ejGrid control.
For an example we have change “EmployeeID” column, normal text box into ejDropDownList when the cell has the value.
Refer the below code example.
<script type="text/javascript">var Data = [{ OrderID: '10248', CustomerID: 'VINET', EmployeeID:'1', Employee:{Address:'India'},Freight:'33.38',ShipName:'Alfreds Futterkiste',ShipCountry:'Brazil'},-------------------];var data = ej.DataManager(Data).executeLocal(ej.Query().select("EmployeeID"));$(function () {$("#Grid").ejGrid({dataSource: Data,allowPaging: true,editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, editMode: "batch" },columns: [------------------],cellEdit: function(e){if(e.columnName == "EmployeeID" && !(e.value == ""))setTimeout(function (e) {if($('.e-ejinputtext').val() != "")$('.e-ejinputtext').ejDropDownList({dataSource:data,value:$('.e-ejinputtext').val()}); //Change the input text box into ejDropDownList when cell has value}, 2);}});});</script>
We have prepared a JsPlayground sample in the following link.
Refer the help documentation.
Regards,Thavasianand S.
$("#Grid").ejGrid({ // the datasource "window.gridData" is referred from jsondata.min.js dataSource: Data, allowPaging: true, allowScrolling: true, editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true , editMode:"batch"}, toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] }, columns: [ ------------- { field: "EmployeeID", headerText: 'Employee ID', editType: ej.Grid.EditingType.Dropdown, textAlign: ej.TextAlign.Right, width: 80 }, ], cellSave: function(e){ if (e.columnName == "EmployeeID") //for EmployeeID column setTimeout(function (e) { if ($('.e-grid .e-gridcontent tr td.e-selectionbackground').hasClass("e-updatedtd")) // If the cell has the red corner updatetd { var inputelement = ej.buildTag("input#" + ".dropdownsave" ); inputelement.attr('type', 'text'); var data = ej.DataManager(Data).executeLocal(ej.Query().select("EmployeeID")); var selectedDropDown = $('.e-grid .e-gridcontent tr').find("td.e-updatedtd.e-selectionbackground"); selectedDropDown.empty(); selectedDropDown.append(inputelement); selectedDropDown.find('.dropdownsave').ejDropDownList({ dataSource: data, value: args.value,width:selectedDropDown.width() }); //appended input element changed to ejDropDownList } }, 2); } }); |