create datagrid frontend oroCommerce - datagrid
I’m creating a datagrid in the frontend but it appears in the layout.
I can see the error
bundle/Resources/views/layouts/default/mayorista_resume_accout_frontend_index/layout.yml
layout:
imports:
-
id: datagrid
root: __root
actions:
- '#setBlockTheme':
themes: 'layout.html.twig'
- '#remove':
id: bloque_resumen
- '#setOption':
id: __datagrid
optionName: grid_name
optionValue: frontend-requests-grid
- '#add':
id: manufacturer_datagrid
blockType: block
parentId: page_content
prepend: false
- '#addTree':
items:
resume_view_page:
blockType: container
resume_container:
blockType: container
resume_body:
blockType: container
resume_body_column_left:
blockType: container
options:
additional_block_prefixes: ['resume_body_column']
resume_body_column_right:
blockType: container
options:
additional_block_prefixes: ['resume_body_column']
resume_after_line_items_grid:
blockType: container
resume_body_container:
blockType: container
options:
additional_block_prefixes: ['resume_body_block_container']
tree:
page_content:
resume_view_page:
resume_container:
resume_body:
resume_body_container:
resume_body_column_left:
bundle/Resources/config/oro/datagrids.yml
datagrids:
app-resumes-grid:
options:
frontend: true
source:
type: orm
query:
select:
- resume.id
- resume.name
- resume.lastname
from:
- { table: MayoristanetResumeAccountBundle:Resume, alias: resume }
columns:
id:
label: ID
frontend_type: integer
name:
label: Name
frontend_type: string
lastname:
label: Lastname
frontend_type: string
sorters:
columns:
id:
data_name: resume.id
name:
data_name: resume.name
lastname:
data_name: resume.lastname
default:
name: DESC
filters:
columns:
id:
type: number
data_name: resume.id
name:
type: string
data_name: resume.name
lastname:
type: string
data_name: resume.lastname
bundle/Resources/views/layouts/default/mayorista_resume_account_frontend_index/layout.html.twig
{% block _manufacturer_datagrid_widget %}
{% import 'OroDataGridBundle::macros.html.twig' as dataGrid %}
{% block content %}
{{ dataGrid.renderGrid('app-resumes-grid') }}
{% endblock %}
{% endblock %}
it does not show any error generates the code and then disappears.
the only thing he says is
Uncaught TypeError: Cannot read property 'datagrid' of undefined
the code generate is this
{"el":"#grid-app-resumes-grid-275870322","gridName":"app-resumes-grid","builders":["orofilter\/js\/datafilter-builder","orosync\/js\/content\/grid-builder","orodatagrid\/js\/totals-builder"],"metadata":{"requireJSModules":["orofilter\/js\/datafilter-builder","orosync\/js\/content\/grid-builder","orodatagrid\/js\/totals-builder"],"options":{"gridName":"app-resumes-grid","frontend":true,"show_grid":true,"additional_fields":[],"toolbarOptions":{"placement":{"bottom":true,"top":true},"hide":false,"addResetAction":true,"addRefreshAction":true,"addColumnManager":true,"turnOffToolbarRecordsNumber":0,"pageSize":{"hide":false,"default_per_page":25,"items":[10,25,50,100]},"pagination":{"hide":false,"onePage":false},"addSorting":false,"disableNotSelectedOption":false},"urlParams":{"originalRoute":"mayorista_resume_account_frontend_index"},"route":"oro_frontend_datagrid_index","contentTags":["Mayoristanet_ResumeAccountBundle_Entity_Resume_type_collection"],"multipleSorting":false,"url":"\/neworo\/web\/app_dev.php\/datagrid\/app-resumes-grid?app-resumes-grid%5BoriginalRoute%5D=mayorista_resume_account_frontend_index"},"lazy":true,"massActions":[],"rowActions":{"update":{"type":"button-widget","label":"Edit","rowAction":false,"link":"#","icon":"pencil-square-o","order":510,"name":"update","frontend_type":"button-widget","launcherOptions":{"onClickReturnValue":true,"runAction":true,"className":"no-hash","widget":[],"messages":[]}},"delete":{"type":"button-widget","label":"Delete","rowAction":false,"link":"#","icon":"trash-o","order":520,"name":"delete","frontend_type":"button-widget","launcherOptions":{"onClickReturnValue":true,"runAction":true,"className":"no-hash","widget":[],"messages":[]}}},"initialState":{"gridView":"__all__","filters":[],"columns":{"id":{"order":0,"renderable":true},"name":{"order":1,"renderable":true},"lastname":{"order":2,"renderable":true},"phone":{"order":3,"renderable":true},"age":{"order":4,"renderable":true}},"currentPage":1,"pageSize":25,"totals":null,"sorters":{"id":"DESC"}},"state":{"gridView":"__all__","filters":[],"columns":{"id":{"order":0,"renderable":true},"name":{"order":1,"renderable":true},"lastname":{"order":2,"renderable":true},"phone":{"order":3,"renderable":true},"age":{"order":4,"renderable":true}},"currentPage":1,"pageSize":25,"totals":null,"sorters":{"id":"DESC"}},"gridViews":{"views":[{"name":"__all__","label":"__all__","icon":"fa-table","appearanceType":"grid","appearanceData":[],"type":"system","filters":[],"sorters":[],"columns":[],"editable":false,"deletable":false,"is_default":false,"shared_by":null}],"gridName":"app-resumes-grid","permissions":{"VIEW":true,"CREATE":true,"EDIT":true,"DELETE":true,"SHARE":true,"EDIT_SHARED":true}},"filters":[{"name":"id","label":"ID","choices":[{"attr":[],"label":"equals","value":"3","data":3},{"attr":[],"label":"not equals","value":"4","data":4},{"attr":[],"label":"equals or greater than","value":"1","data":1},{"attr":[],"label":"greater than","value":"2","data":2},{"attr":[],"label":"equals or less than","value":"5","data":5},{"attr":[],"label":"less than","value":"6","data":6},{"attr":[],"label":"is any of","value":"9","data":9},{"attr":[],"label":"is not any of","value":"10","data":10},{"attr":[],"label":"is empty","value":"filter_empty_option","data":"filter_empty_option"},{"attr":[],"label":"is not empty","value":"filter_not_empty_option","data":"filter_not_empty_option"}],"type":"number","enabled":true,"visible":true,"translatable":true,"force_like":false,"case_insensitive":true,"min_length":0,"max_length":9223372036854775807,"lazy":false,"formatterOptions":{"decimals":0,"grouping":false,"orderSeparator":"","decimalSeparator":","},"arraySeparator":",","arrayOperators":[9,10],"dataType":"data_integer","cacheId":null},{"name":"name","label":"Name","choices":[{"attr":[],"label":"contains","value":"1","data":1},{"attr":[],"label":"does not contain","value":"2","data":2},{"attr":[],"label":"is equal to","value":"3","data":3},{"attr":[],"label":"starts with","value":"4","data":4},{"attr":[],"label":"ends with","value":"5","data":5},{"attr":[],"label":"is any of","value":"6","data":6},{"attr":[],"label":"is not any of","value":"7","data":7},{"attr":[],"label":"is empty","value":"filter_empty_option","data":"filter_empty_option"},{"attr":[],"label":"is not empty","value":"filter_not_empty_option","data":"filter_not_empty_option"}],"type":"string","enabled":true,"visible":true,"translatable":true,"force_like":false,"case_insensitive":true,"min_length":0,"max_length":9223372036854775807,"lazy":false,"cacheId":null},{"name":"lastname","label":"Lastname","choices":[{"attr":[],"label":"contains","value":"1","data":1},{"attr":[],"label":"does not contain","value":"2","data":2},{"attr":[],"label":"is equal to","value":"3","data":3},{"attr":[],"label":"starts with","value":"4","data":4},{"attr":[],"label":"ends with","value":"5","data":5},{"attr":[],"label":"is any of","value":"6","data":6},{"attr":[],"label":"is not any of","value":"7","data":7},{"attr":[],"label":"is empty","value":"filter_empty_option","data":"filter_empty_option"},{"attr":[],"label":"is not empty","value":"filter_not_empty_option","data":"filter_not_empty_option"}],"type":"string","enabled":true,"visible":true,"translatable":true,"force_like":false,"case_insensitive":true,"min_length":0,"max_length":9223372036854775807,"lazy":false,"cacheId":null},{"name":"phone","label":"Phone","choices":[{"attr":[],"label":"equals","value":"3","data":3},{"attr":[],"label":"not equals","value":"4","data":4},{"attr":[],"label":"equals or greater than","value":"1","data":1},{"attr":[],"label":"greater than","value":"2","data":2},{"attr":[],"label":"equals or less than","value":"5","data":5},{"attr":[],"label":"less than","value":"6","data":6},{"attr":[],"label":"is any of","value":"9","data":9},{"attr":[],"label":"is not any of","value":"10","data":10},{"attr":[],"label":"is empty","value":"filter_empty_option","data":"filter_empty_option"},{"attr":[],"label":"is not empty","value":"filter_not_empty_option","data":"filter_not_empty_option"}],"type":"number","enabled":true,"visible":true,"translatable":true,"force_like":false,"case_insensitive":true,"min_length":0,"max_length":9223372036854775807,"lazy":false,"formatterOptions":{"decimals":0,"grouping":false,"orderSeparator":"","decimalSeparator":","},"arraySeparator":",","arrayOperators":[9,10],"dataType":"data_integer","cacheId":null},{"name":"age","label":"Age","choices":[{"attr":[],"label":"equals","value":"3","data":3},{"attr":[],"label":"not equals","value":"4","data":4},{"attr":[],"label":"equals or greater than","value":"1","data":1},{"attr":[],"label":"greater than","value":"2","data":2},{"attr":[],"label":"equals or less than","value":"5","data":5},{"attr":[],"label":"less than","value":"6","data":6},{"attr":[],"label":"is any of","value":"9","data":9},{"attr":[],"label":"is not any of","value":"10","data":10},{"attr":[],"label":"is empty","value":"filter_empty_option","data":"filter_empty_option"},{"attr":[],"label":"is not empty","value":"filter_not_empty_option","data":"filter_not_empty_option"}],"type":"number","enabled":true,"visible":true,"translatable":true,"force_like":false,"case_insensitive":true,"min_length":0,"max_length":9223372036854775807,"lazy":false,"formatterOptions":{"decimals":0,"grouping":false,"orderSeparator":"","decimalSeparator":","},"arraySeparator":",","arrayOperators":[9,10],"dataType":"data_integer","cacheId":null}],"columns":[{"label":"ID","style":"integer","type":"integer","translatable":true,"editable":false,"shortenableLabel":true,"name":"id","order":0,"renderable":true,"sortable":true},{"label":"Name","type":"string","translatable":true,"editable":false,"shortenableLabel":true,"name":"name","order":1,"renderable":true,"sortable":true},{"label":"Lastname","type":"string","translatable":true,"editable":false,"shortenableLabel":true,"name":"lastname","order":2,"renderable":true,"sortable":true},{"label":"Phone","style":"integer","type":"integer","translatable":true,"editable":false,"shortenableLabel":true,"name":"phone","order":3,"renderable":true,"sortable":true},{"label":"Age","style":"integer","type":"integer","translatable":true,"editable":false,"shortenableLabel":true,"name":"age","order":4,"renderable":true,"sortable":true}],"gridParams":[],"enableFloatingHeaderPlugin":false},"data":{"data":[{"id":2,"name":"Martin","lastname":"Asd","phone":6597979,"age":29,"action_configuration":{"update":false,"delete":false}},{"id":1,"name":"Marcos","lastname":"Prosperi","phone":1169560852,"age":30,"action_configuration":{"update":false,"delete":false}}],"options":{"hideToolbar":false,"totalRecords":2,"totals":[]}},"enableFilters":true,"enableToggleFilters":true,"filterContainerSelector":null,"filtersStateElement":null,"enableViews":true,"showViewsInNavbar":false,"showViewsInCustomElement":false,"inputName":"app-resumes-grid","themeOptions":[],"toolbarOptions":[],"gridViewsOptions":[],"gridBuildersOptions":[]}
dont show datagrid
I could solve it using this
{% block _manufacturer_datagrid_widget %}
{% import 'OroDataGridBundle::macros.html.twig' as dataGrid %}
{% include 'OroDataGridBundle:js:toolbar.html.twig' %}
<div class="js-frontend-datagrid-grid-views-tpl"></div>
{% block content %}
{{ dataGrid.renderGrid('app-resumes-grid') }}
{% endblock %}
{% endblock %}
Related
OroPlatform: override oro_datetime_widget options
Context I am actually trying to change the default placeholder for the time input of the OroDateTimeType::class. I want to have, for example, the text Horaires instead of Temps. Here is my form field in my FormType : ->add('expirationDate', OroDateTimeType::class, [ 'label' => 'app.subscription.fields.expirationDate', ]) And in my twig view : form_row(form.expirationDate) Issue At the beginning, I have tried to used the Symfony 4 placeholder option for DateTime type : https://symfony.com/doc/4.4/reference/forms/types/date.html#placeholder. It doesn't work because OroDateTime use a different datepicker and it override the Symfony values on load : {# vendor/oro/platform/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig #} {% block oro_datetime_widget %} {% set dateValidation = {'Date' : {}} %} {% set timeValidation = {'Time' : {}} %} {% if required %} {% set dateValidation = dateValidation|merge({'NotBlank' : {}}) %} {% set timeValidation = timeValidation|merge({'NotBlank' : {}}) %} {% endif %} {% if attribute(attr, 'class') is defined %} {% set attrClass = attr['class'] %} {% else %} {% set attrClass = '' %} {% endif %} {% set options = { view: 'oroui/js/app/views/datepicker/datetimepicker-view', nativeMode: isMobileVersion(), dateInputAttrs: { placeholder: 'oro.form.choose_date'|trans, id: id, name: id, class: 'input-small datepicker-input ' ~ attrClass, 'data-validation': dateValidation|json_encode(constant('JSON_FORCE_OBJECT')), 'aria-live': 'assertive', autocomplete: 'off', autocorrect: 'off', autocapitalize: 'off' }, datePickerOptions: { altFormat: 'yy-mm-dd', changeMonth: true, changeYear: true, yearRange: years|default('-80:+1'), showButtonPanel: true }, timeInputAttrs: { placeholder: 'oro.form.choose_time'|trans, id: 'time_selector_' ~ id, name: 'time_selector_' ~ id, class: 'input-small timepicker-input ' ~ attrClass, 'data-validation': timeValidation|json_encode(constant('JSON_FORCE_OBJECT')) }, timePickerOptions: { } } %} {% set id = 'hidden_' ~ id %} {% set attr = attr|merge({ 'data-page-component-module': 'oroui/js/app/components/view-component', 'data-page-component-options': options|json_encode(constant('JSON_FORCE_OBJECT')) }) %} {{ block('datetime_widget') }} {% endblock oro_datetime_widget %} If I change the value timeInputAttrs.placeholder from the options variable. It works. But, I want to pass this variable to my specific form field, not globally. UPDATE I finally choose to change the oro.form.choose_time translation in my project globally. So, in my Resources/translations/messages.fr_FR.yml I've created these lines : oro: form: choose_time: Horaires auth: description: main: Baltimore Then, I've understand that translations are generated in a file located in var/cache/dev/translations/catalogue.fr_FR : <?php use Symfony\Component\Translation\MessageCatalogue; $catalogue = new MessageCatalogue('fr_FR', array ( 'messages' => array ( 'oro.form.choose_time' => 'Temps', 'oro.auth.description.main' => 'Baltimore', Here, I can see that the oro.auth.description.main change is applied, but the value for the key oro.form.choose_time is still the same. Maybe I have a command to run ?
The easiest way to override any text in the Oro application UI is to override a translation for the message used to render it. As the form placeholder is translated as well, you can use this technic. If it's the only customization you need for the form, follow this guide. If you want to override an HTML, you can extend the template by following the template overriding guide. But, as you want to modify the label for a single form, then the best way would be to extend the form type and override the single form field with new options.
OroPlatform: override Oro bundle template
Context I'm trying to override the following template : vendor/oro/platform/src/Oro/Bundle/OrganizationBundle/Resources/views/BusinessUnit/update.html.twig This template seems to belong to the OroOrganizationBundle bundle. Issue So, I have tried to put my override in the following path : templates/bundles/OroOrganizationBundle/BusinessUnit/update.html.twig according to Symfony 4.X documentation : https://symfony.com/doc/4.4/bundles/override.html#templates I have cleared the cache : symfony console cache:clear but nothing changes. Here is my override template : {% extends 'OroOrganizationBundle:BusinessUnit:update.html.twig' %} {% block content_data %} {% set id = 'business_unit-profile' %} {% set dataBlocks = [{ 'title': 'General'|trans, 'class': 'active', 'subblocks': [{ 'title': '', 'data': [ form_widget(form.appendUsers, {'id': 'businessUnitAppendUsers'}), form_widget(form.removeUsers, {'id': 'businessUnitRemoveUsers'}), form_row(form.name), form_row(form.parentBusinessUnit), form_row(form.phone), form_row(form.website), form_row(form.email), form_row(form.fax), ] }] }] %} {% set dataBlocks = dataBlocks|merge(oro_form_additional_data(form, 'Additional Override'|trans)) %} {% set dataBlocks = dataBlocks|merge([{ 'title' : 'oro.organization.businessunit.users.label'|trans, 'subblocks': [{ 'title' : null, 'useSpan': false, 'data' : [dataGrid.renderGrid(gridName, {business_unit_id: entityId}, { cssClass: 'inner-grid' })] }] }] ) %} {% set data = { 'formErrors': form_errors(form)? form_errors(form) : null, 'dataBlocks': dataBlocks } %} {{ parent() }} {% endblock content_data %} Here is the output of the following command line : symfony console debug:twig | grep Organization
Finally, I found a solution using this article from Oro documentation : https://doc.oroinc.com/frontend/back-office/templates/ The right path for my case was : src/Resources/OroOrganizationBundle/views/BusinessUnit/update.html.twig I have tried to use the "extends" method from the Symfony documentation : https://symfony.com/doc/4.4/bundles/override.html#templates which consist to override only a specific block part. In my case, I needed to copy the entire file but it works.
Sonata admin bundle: exclude custom admin from global search
Within my Symfony 3.4 project, I have 2 custom admins. Specially created for reporting services. Those admins do not have specific entities. For the custom admins, I followed the Symfony recipe: https://symfony.com/doc/3.x/bundles/SonataAdminBundle/cookbook/recipe_custom_view.html Now, when searching items through the sonata global search, I get a "Class does not exist" error in vendor/sonata-project/admin-bundle/src/Resources/views/Core/search.html.twig. This error is related to the custom admins. Is there a solution to exclude these custom admins from the global search or to resolve this error? Admin: <?php namespace MainBundle\Admin; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Route\RouteCollection; class AccessRightsAdmin extends AbstractAdmin { protected $baseRoutePattern = 'accessrights'; protected $baseRouteName = 'Accessrights'; protected function configureRoutes(RouteCollection $collection) { $collection->clearExcept(array('list')); $collection->add('accesRights', 'accessrights'); } } Service services: system.admin.accessrights: class: MainBundle\Admin\AccessRightsAdmin arguments: [~, ~, MainBundle:AccessRightsAdmin] tags: - { name: sonata.admin, manager_type: orm, group: sonata.admin.group.System, label: Accessrights } calls: - [ setTranslationDomain, [SonataAdminBundle]] public: true
I found a solution and I'm going to leave it here in case someone need it. The solution basically is to override the search.html.twig and ignore the admin you want from the search like so: {% extends base_template %} {% block title %}{{ 'title_search_results'|trans({'%query%': query}, 'SonataAdminBundle') }}{% endblock %} {% block breadcrumb %}{% endblock %} {% block content %} <h2 class="page-header">{{ 'title_search_results'|trans({'%query%': query}, 'SonataAdminBundle') }}</h2> {% if query is defined and query is not same as(false) %} {% set count = 0 %} <div class="row" data-masonry='{ "itemSelector": ".search-box-item" }'> {% for group in groups %} {% set display = group.roles is empty or is_granted(sonata_admin.adminPool.getOption('role_super_admin')) or group.roles|filter(role => is_granted(role))|length > 0 %} {% if display %} {% for admin in group.items %} {% set count = count + 1 %} {% if admin.code != 'bundle.admin.admin_to_ignore' %}{# in this line right here add the admin you want to ignore in your search #} {% if admin.hasRoute('create') and admin.hasAccess('create') or admin.hasRoute('list') and admin.hasAccess('list') %} {{ sonata_block_render({ 'type': 'sonata.admin.block.search_result' }, { 'query': query, 'admin_code': admin.code, 'page': 0, 'per_page': 10, 'icon': group.icon }) }} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %} </div> {% endif %} {% endblock %} To override the file you need to put it under the following path: app -> Resources -> SonataAdminBundle -> views -> Core -> search.html.twig
How can I set a variable with twig?
I want to set the variable key before using it "columns": [ {% for key, value in columns %} {"data": "{{ key }}"}, {% endfor %} { "data": "id" } ] My approach: "columns": [ {% for key, value in columns %} {% set result = '{{ key }}' %} {"data": "{{ result }}"}, {% endfor %} { "data": "id" } ] But it is not working. I get the error message: Requested unknown parameter '{{ key }}'
{% set result = key %} From what I see, you want to set the value of result variable, result of key is already set, you just didn't access it correctly.
How to access Symfony image filter settings from twig
I would like to build a macro, which automatically reads the image's width and height of the corresponding filter. Let's say, this is a part of my images.yml liip_imagine: filter_sets: original: path: original quality: 80 small: path: small quality: 75 filters: thumbnail: { size: [400, 400], mode: inset } How can I re-use the size in my Twig macro? {% macro img(media, filter) %} {% spaceless %} <img src="{{ media.filename|imagine_filter(filter) }}" alt="" {# is there something like this? #} width="{{ imagine_get_filter(filter).filters[0].size[0] }}" height="{{ imagine_get_filter(filter).filters[0].size[1] }}" /> {% endspaceless %} {% endmacro %}