<?php
$columns = array();
foreach ($model->attributes as $attributeName => $attributeValue) {

    $columns[] = array(
        'name' => $attributeName,
        'header' => $model->getAttributeLabel($attributeName),
        'headerHtmlOptions' => array('data-translation-id' => 'BLACKLIST_MODEL_' . strtoupper($attributeName)),
    );
}
$columns[] = array(
    'class' => 'ext.PlGrid.PlCButtonColumn',
    'template' => '{ajaxUpdate}{delete}'
);


$this->widget('ext.PlGrid.PlGridView', array(
    'id' => 'blacklist-grid',
    'headerTitle' => 'Header_title', // optional
    'addButtonTitle' => 'ADD_NEW_BLACKLIST', // optional
    'modalCreateHeader' => 'BLACKLIST_HEADER_CREATE', // optional
    'modalUpdateHeader' => 'BLACKLIST_HEADER_UPDATE', // optional
    'afterAjaxUpdate' => 'function(){
            setCreateButtonVisibility();
        }',
    'headerAttribute' => 'name',
    'itemsCssClass' => 'plTable items',
    'enableSearchButton' => false,
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => $columns,
    'customButtons' => $this->getTabItems($modelName),
        )
);
$routingBlackListMax = PhonalisaLicenseManager::routingBlacklistMax();
?>
<script>
    function setCreateButtonVisibility() {
        if (
                $("#blacklist-grid tbody tr").length >= <?php echo $routingBlackListMax; ?>
        && !$("#blacklist-grid tbody tr td:first-child").hasClass("empty")
                && <?php echo $routingBlackListMax; ?> >= 0
                ) {
            $("#blacklist-gridCreateBtn").hide();
        } else {
            $("#blacklist-gridCreateBtn").show();
        }
    }
    setCreateButtonVisibility();
</script>