Git Product home page Git Product logo

Comments (2)

budzik avatar budzik commented on June 2, 2024 1

Hi, here's a piece of code. Keep in mind that this is only a guideline.
Take a look at https://symfony.com/bundles/EasyAdminBundle/current/design.html#overriding-templates for more information.

//YourCrudController

#[\Override]
public function configureCrud(Crud $crud): Crud
{
    return $crud
        ->overrideTemplate('crud/index', 'admin/index/my_index.html.twig')
    ;
}

//templates/admin/index/my_index.html.twig

This a copy of \vendor\easycorp\easyadmin-bundle\src\Resources\views\crud\index.html.twig
I removed all blocks except {% block table_body %}
commented code with (!!) I added on the fly
at the end of the table should appear a row summing identifiers (id)
hope it helps. Cheers and GL!

{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
{# @var entities \EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection #}
{# @var paginator \EasyCorp\Bundle\EasyAdminBundle\Orm\EntityPaginator #}
{% extends '@!EasyAdmin/crud/index.html.twig' %}

// !!set the idSumValue to 0
{% set idSumValue = 0 %}

{% block table_body %}
    {% for entity in entities %}
        {% if entity.isAccessible %}

            <tr data-id="{{ entity.primaryKeyValueAsString }}">
                {% if has_batch_actions %}
                    <td class="batch-actions-selector">
                        <div class="form-check">
                            <input type="checkbox" class="form-check-input form-batch-checkbox" id="form-batch-checkbox-{{ loop.index0 }}" value="{{ entity.primaryKeyValue }}">
                        </div>
                    </td>
                {% endif %}

                {% for field in entity.fields %}
                    {% set is_searchable = null == ea.crud.searchFields or field.property in ea.crud.searchFields %}

                    <td data-column="{{ field.property }}" data-label="{{ field.label|trans|e('html_attr') }}" class="{{ is_searchable ? 'searchable' }} {{ field.property == sort_field_name ? 'sorted' }} text-{{ field.textAlign }} {{ field.cssClass }}" dir="{{ ea.i18n.textDirection }}">
                        {{ include(field.templatePath, { field: field, entity: entity }, with_context = false) }}
                    </td>

                    // !!count idSumValue
                    {% if field.property == 'id' %}
                        {% set idSumValue = idSumValue + field.value %}
                    {% endif %}

                {% endfor %}

                {% block entity_actions %}
                    <td class="actions {{ ea.crud.showEntityActionsAsDropdown ? 'actions-as-dropdown' }}">
                        {% if entity.actions.count > 0 %}
                            {% if ea.crud.showEntityActionsAsDropdown %}
                                <div class="dropdown dropdown-actions">
                                    <a class="dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                        {# don't use FontAwesome 'fa-ellipsis-h' icon here because it doesn't look good #}
                                        {# this icon is 'dots-horizontal' icon from https://heroicons.com/ #}
                                        <svg xmlns="http://www.w3.org/2000/svg" height="21" width="21" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z" />
                                        </svg>
                                    </a>

                                    <div class="dropdown-menu dropdown-menu-right">
                                        {% for action in entity.actions %}
                                            {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: ea.crud.showEntityActionsAsDropdown }, with_context = false) }}
                                        {% endfor %}
                                    </div>
                                </div>
                            {% else %}
                                {% for action in entity.actions %}
                                    {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: ea.crud.showEntityActionsAsDropdown }, with_context = false) }}
                                {% endfor %}
                            {% endif %}
                        {% endif %}
                    </td>
                {% endblock entity_actions %}
            </tr>

        {% endif %}
    {% else %}
        {% block table_body_empty %}
            {% for i in 1..14 %}
                <tr class="empty-row">
                    <td><span></span></td>
                    <td><span></span></td>
                    <td><span></span></td>
                    <td><span></span></td>
                    <td><span></span></td>
                    <td><span></span></td>
                </tr>

                {% if 3 == loop.index %}
                    <tr class="no-results">
                        <td colspan="100">
                            {{ t('datagrid.no_results', ea.i18n.translationParameters, 'EasyAdminBundle')|trans }}
                        </td>
                    </tr>
                {% endif %}
            {% endfor %}
        {% endblock table_body_empty %}

    {% endfor %}

    // !!display the idSumValue
    <tr>
        <td colspan="100">
            {{ idSumValue }}
        </td>
    </tr>

    {% if some_results_are_hidden %}
        <tr class="datagrid-row-empty">
            <td class="text-center" colspan="100">
                <span class="datagrid-row-empty-message"><i class="fa fa-lock mr-1"></i> {{ 'datagrid.hidden_results'|trans({}, 'EasyAdminBundle') }}</span>
            </td>
        </tr>
    {% endif %}
{% endblock table_body %}

from easyadminbundle.

wehostadm avatar wehostadm commented on June 2, 2024

@budzik Thanks for your help :)
I think this feature could be good to implement in EasyAdmin

from easyadminbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.