4
votes

I have implemented editable AG-Grid. In the grid, one of the column displays country of the player as shown below:

enter image description here

Now in last column, when user click on the cell, I want to display list of available countries as a dropdown.

Here by default AG-Grid displays normal dropdown. Which I want to replace with Bootstrap-select.

To achieve this, I have implemented custom selector and using Bootstrap-select library.

But when cell is clicked, Dropdown is not being rendered. I am not getting any error though in console.

Here is the code of my custom cell-editor:

var selectCellEdior = function () { };
selectCellEdior.prototype = {
    init: function (params) {

        selector = document.createElement('select');

        for(var i = 0; i < params.values.length; i++) {
          var option = params.values[i];
          $('<option />', { value: option, text: option }).appendTo(selector);
        }

        this.cellSelector = selector;

        $(this.cellSelector).selectpicker({ size: 'auto' });


    },
    getValue: function () {
        return $(this.cellSelector).find('.btn-text').text();
    },
    getGui: function () {
        return this.cellSelector;
    },
    destroy: function () {
        $(this.cellSelector).remove();
    }
};

Here is the Sample Code

I dont understand what is the issue.

2

2 Answers

1
votes

The problem is the selectpicker jQuery method seems to add a display: none to the select element. Ag-Grid is adding it to the DOM you just can't see it. Additionally the getValue function is not returning the selected option's text.

The following changes to getValue and getGui will make the grid work:

  ...
  getValue: function () {
    return $(this.cellSelector).val();
  },
  getGui: function () {
    this.cellSelector.style.display = 'block';
    return this.cellSelector;
  },
  ...

Here is the modified Plunker

0
votes

For anyone looking at this now.... Ag-grid has a method afterGuiAttached that is called after the GUI has been attached to the Grid's cell. If you're noticing that the bootstrap-select still isn't "quite right" after following the instructions above, put ALL of the calls to selectpicker in afterGuiAttached instead of init or getGui. This will place the bootstrap-select into a div with the right classes it needs (dropdown, bootstrap-select, etc), and create all of the bootstrap-select elements that are properly shown/hidden.