2

I'm still using Angular 1.x and ag-Grid (non-enterprise).

But I'm trying to add tooltips from angular ui-bootstrap. So I need to add an attribute to all headers: "uib-tooltip='headerValue' "

The issue is that it wants me to implement a whole new component. But the example component they put on the ag-grid website is super complicated and different from the default functionality. Why isn't there an easy way of doing these things?

Why deprecate headerTemplate?

So even if I want a slight change from the default headers, I basically need to take over responsibility for everything. And I don't even have the original version of header component as example code.

I just want to add some new HTML to the header that doesn't involve taking responsibility for sorting, field, menu etc.

1 Answer 1

1

I know this is old but...I was in this exact situation, where I was wondering why it wasn't provided... I went ahead and built my own which wasn't extremely hard. Since I think someone might find a default header component useful: here's one that is essentially the default

Note you'll need font awesome for the icons and make sure to use the custom component in your column options.

    function customHeaderComponent() {
    }

    customHeaderComponent.prototype.init = function (agParams) {
        this.agParams = agParams;
        this.eGui = document.createElement('div');
        this.eGui.innerHTML = '' +
            '<span class="customHeaderLabel">' + this.agParams.displayName + '</span> ' +
            '<span class="customSortDownLabel inactive"><i class="fa fa-caret-down""></i> </span>' +
            '<span class="customSortUpLabel inactive"><i class="fa fa-caret-up""></i> </span>'+
            '<span class="customFilterLabel inactive"><i class="fa fa-filter"></i> </span>'+
            '<span class="customHeaderMenuButton"><i class="fa fa-tasks""></i></span>'
        ;

        this.eMenuButton = this.eGui.querySelector(".customHeaderMenuButton");
        this.eLabel = this.eGui.querySelector(".customHeaderLabel");
        this.eSortDownButton = this.eGui.querySelector(".customSortDownLabel");
        this.eSortUpButton = this.eGui.querySelector(".customSortUpLabel");
        this.eFilterInd = this.eGui.querySelector(".customFilterLabel");


        if (this.agParams.enableMenu) {
            this.onMenuClickListener = this.onMenuClick.bind(this);
            this.eMenuButton.addEventListener('click', this.onMenuClickListener);
        } else {
            this.eGui.removeChild(this.eMenuButton);
        }

        if (this.agParams.enableSorting) {
            this.eLabel.addEventListener('click', this.changeSort.bind(this));

            this.onSortChangedListener = this.onSortChanged.bind(this);
            this.agParams.column.addEventListener('sortChanged', this.onSortChangedListener);
            this.onSortChanged();
        }
        var self = this;
        self.eFilterInd.hidden = !self.agParams.column.isFilterActive();
        this.agParams.column.addEventListener('filterChanged', function() {
            self.eFilterInd.hidden = !self.agParams.column.isFilterActive();
        });

    };

    customHeaderComponent.prototype.changeSort = function (event) {
        this.agParams.progressSort(event);
    }


    customHeaderComponent.prototype.onSortChanged = function () {
        function deactivate(toDeactivateItems) {
            toDeactivateItems.forEach(function (toDeactivate) {
                toDeactivate.hidden = true;
            });
        }

        function activate(toActivate) {
            toActivate.hidden = false;
        }

        if (this.agParams.column.isSortAscending()) {
            deactivate([this.eSortUpButton]);
            activate(this.eSortDownButton)
        } else if (this.agParams.column.isSortDescending()) {
            deactivate([this.eSortDownButton]);
            activate(this.eSortUpButton)
        } else {
            deactivate([this.eSortUpButton, this.eSortDownButton]);
        }
    };

    customHeaderComponent.prototype.getGui = function () {
        return this.eGui;
    };

    customHeaderComponent.prototype.onMenuClick = function () {
        this.agParams.showColumnMenu(this.eMenuButton);
    };

    customHeaderComponent.prototype.onSortRequested = function (order, event) {
        this.agParams.setSort(order, event.shiftKey);
    };

    customHeaderComponent.prototype.destroy = function () {
        if (this.onMenuClickListener) {
            this.eMenuButton.removeEventListener('click', this.onMenuClickListener)
        }
    };
Sign up to request clarification or add additional context in comments.

2 Comments

Yes the main issue is that there is a ton of code to write, and there's two ways to write it (one old, one new with ES script).
How do we use Angular.js templates inside the header? I used to have <span ng-bind="colDef.headerName"></span> and does not seem to work when using Header Component. No documentation...

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.