open-orchestra/open-orchestra-cms-bundle

View on GitHub
BackofficeBundle/Resources/public/ecmascript/OpenOrchestra/Service/Form/Behavior/ScrollTable.js

Summary

Maintainability
A
0 mins
Test Coverage
import AbstractBehavior from 'OpenOrchestra/Service/Form/Behavior/AbstractBehavior'

/**
 * @class ScrollTable
 */
class ScrollTable extends AbstractBehavior
{
    /**
     * activate behavior
     *
     * @param {Object} $element - jQuery object
     */
    activate($element) {
        let $fixedColumn = $element.clone().addClass('clone');
        $fixedColumn.find('th:not(:first-child),td:not(:first-child)').remove();
        $fixedColumn.insertBefore($element);
        $element.wrap($('<div>').addClass('wraper table-responsive'));
        $fixedColumn.find('tr').each(function (i, elem) {
            $(this).height($element.find('tr:eq(' + i + ')').height());
        });
    }

    /**
     * return selector
     *
     * @return {String}
     */
    getSelector() {
        return 'table.scrollable';
    }
}

// unique instance of ScrollTable
export default (new ScrollTable);