0

I recently started using ui-grid and I want that when the grid initializes, each column will have width according to its content.

I know there is a function that does that in ui-grid when the user double-clicks a cell to resize (resizer.link.dblClickFn) but it doesn't take a column as a parameter, it takes an event of a column click.

Anyone has any experience with this?

1
  • This is kludgy but could you not programmatically fire the double click as each cell is populated. This would be costly with large amounts of data but just might work for smaller datasets. Commented Jul 19, 2015 at 17:22

1 Answer 1

4

I was evetually able to solve it by manually calling the double click event on all the resizers :

    onRegisterApi: function (gridApi) {
        $scope.gridApi = gridApi;

        setTimeout(function () {
            var resizers = document.getElementsByClassName("ui-grid-column-resizer");

            for (var i = 0; i < resizers.length; i++) {
                var event = new MouseEvent('dblclick', {
                    'view': window,
                    'bubbles': true,
                    'cancelable': true
                });

                resizers[i].dispatchEvent(event);
            }
        }, 1);
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Solved it for me as the only solution for ui-grid 3.x!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.