Introduction

To add combobox in ag-grid first of all we have to have knowledge of cell render. Through cell render we can edit our ag-grid column with drop down or textbox.
We can bind our dropdown in two ways: statically and dynamically

In this I will show statically how to bind dropdown.



Now In This Image I inserted DropDown.

Firstly let's see the code part of this.
  1. $scope.gridOptions = {
  2. columnDefs: [{
  3. headerName: "CompanyName",
  4. field: "CompanyName",
  5. editable: true,
  6. width: 130
  7. }, {
  8. headerName: 'ProductName',
  9. field: "ProductName",
  10. editable: true,
  11. width: 130
  12. }, {
  13. headerName: "ProjectID",
  14. field: "ProjectID",
  15. editable: true,
  16. width: 100
  17. }, {
  18. headerName: "Status",
  19. field: "Status",
  20. editable: true,
  21. width: 100
  22. }, {
  23. headerName: "Delete",
  24. field: "Delete",
  25. editable: true,
  26. editable: false,
  27. width: 100,
  28. cellRenderer: customEditorImageWQ
  29. }, {
  30. headerName: "Update",
  31. field: "Update",
  32. editable: true,
  33. editable: false,
  34. width: 100,
  35. cellRenderer: customEditor
  36. }, {
  37. headerName: "CompanyName",
  38. field: "CompanyName",
  39. width: 150,
  40. cellRenderer: CustomCombobox
  41. }, ],
  42. rowData: null,
  43. enableColResize: true,
  44. enableSorting: true,
  45. rowSelection: 'multiple',
  46. angularCompileRows: true,
  47. rowDeselection: true,
  48. onRowClicked: RowClick,
  49. enableFilter: true,
  50. editable: true,
  51. suppressRowClickSelection: true,
  52. };
  53. function CustomCombobox(params) {
  54. //Find RowIndex
  55. var rowIndex = params.rowIndex;
  56. //FindColoumn Name
  57. var Column = params.eGridCell.attributes.colId;
  58. //FindGridData
  59. var WeldGridData = $scope.gridOptions.rowData;
  60. //create select element using javascript
  61. var eSelect = document.createElement("select");
  62. //Set attributes
  63. eSelect.setAttribute('class', 'custom-select form-control');
  64. eSelect.setAttribute('style', 'padding:0px');
  65. eSelect.setAttribute('name', params.colDef.field);
  66. eSelect.setAttribute('id', params.colDef.field + "_" + rowIndex);
  67. //get the value of the select option
  68. var value = params.data.CompanyID;
  69. //create the default option of the select element
  70. var eOption = document.createElement("option");
  71. eOption.text = "Select";
  72. eOption.value = "";
  73. eSelect.appendChild(eOption);
  74. if (params.colDef.field == "CompanyName") {
  75. CompanyName = $scope.CompanyList;
  76. var companyid = params.data.CompanyID;
  77. var eOptionVal = document.createElement("option");
  78. //Statical set data in grid ComboBox
  79. eOptionVal.text = "Angra";
  80. eOptionVal.value = 1;
  81. eSelect.appendChild(eOptionVal);
  82. var eOption = document.createElement("option");
  83. eOption.text = "Navcreation";
  84. eOption.value = "2";
  85. eSelect.appendChild(eOption);
  86. }
  87. return eSelect;
  88. }
This Is coding part in js file through this I bind my dropdown


If you want to know how to add dropdown dynamically then visit my blog.
Thanks for visiting; please do comment