Changing the default +/- icon in the responsiveCollapse model

爱⌒轻易说出口 提交于 2021-01-29 05:39:58

问题


The default icon for the responsiveCollapse collapse expand feature in tabulator appears not to be centered. Are there options to change this icon. Maybe a right and down carrot?


回答1:


The responsiveCollapse formatter is just a formatter like all the others, as such you can create one that works however you like.

Here is the build in formatter you can use as a basis for your own:

var customResponsiveCollapseFormatter = function(cell, formatterParams, onRendered){
    var self = this,
    open = false,
    el = document.createElement("div");

    function toggleList(isOpen){
        var collapse = cell.getRow().getElement().getElementsByClassName("tabulator-responsive-collapse")[0];

        open = isOpen;

        if(open){
            el.classList.add("open");
            if(collapse){
                collapse.style.display = '';
            }
        }else{
            el.classList.remove("open");
            if(collapse){
                collapse.style.display = 'none';
            }
        }
    }

    el.classList.add("tabulator-responsive-collapse-toggle");
    el.innerHTML = "<span class='tabulator-responsive-collapse-toggle-open'>+</span><span class='tabulator-responsive-collapse-toggle-close'>-</span>";

    cell.getElement().classList.add("tabulator-row-handle");

    if(self.table.options.responsiveLayoutCollapseStartOpen){
        open = true;
    }

    el.addEventListener("click", function(){
        toggleList(!open);
    });

    toggleList(open);

    return el;
}

The el.innerHTML = line is the one that sets the content of the element, you could add whatever you like in there to customize the output.

You can then assign it in a column definition:

{formatter:customResponsiveCollapseFormatter, headerSort:false},

Full details on how to use custom formatters can be found in the Formatting Documentation



来源:https://stackoverflow.com/questions/54351569/changing-the-default-icon-in-the-responsivecollapse-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!