

function plDynamicGrid(gridId, prototypeRowClass, addButtonSelector, newRowClass, addRowCallbackCallback) {

    this.gridId = gridId;
    this.firstRule = $(this.gridId + ' tbody tr').first();
    this.index = $(this.gridId + ' tbody').find('.icon-trash').length;
    this.addButtonSelector = addButtonSelector;
    this.newRowClass = newRowClass;
    this.addRowCallback = addRowCallbackCallback;
    this.prototypeRowClass = prototypeRowClass;

    this.initAddRow = function() {


        var gridId = this.gridId;
        var index = this.index;
        var firstRule = this.firstRule;
        var newRowClass = this.newRowClass;
        var callback = this.addRowCallback;
        var prototypeRowClass = this.prototypeRowClass;

        $(this.addButtonSelector).click(function () {
            //hinzufügen :
            $(gridId + ' > table').append(firstRule.clone().addClass(newRowClass));
            $(gridId + ' tbody tr:last-child').removeClass(prototypeRowClass);

            $(gridId + ' tbody tr:last-child input').each(function (i, e) {

                e.value = '';
                e.name = e.name.replace('0', index);
                e.id = e.id.replace('0', index);

                callback(e, index);

            });
            var scrolled = $('.modal-body').scrollTop();
            var scroll = scrolled + $(gridId + ' > table > tbody > tr:last-child').height();

            $('.modal-body').animate({scrollTop: scroll}, 300);
            index = index + 1;
        });

    };

    this.initAddRow();
}