ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

This topic contains 1 reply, has 2 voices, and was last updated by  Alexandr Smaga 3 years, 1 month ago.

  • Creator
    Topic
  • #6322
    Ayushi Sangal
    Ayushi Sangal
    Participant

    Hello,

    I am getting error on rendering twig file. I have to pass request parameter to the grid.

    I have created 3 files services.yml, datagrid.yml and my template.

    services.yml

    webmuch-search.event_listener.webmuch-search-grid_parameter_listener:
    class: Webmuch\GroupBundle\EventListener\ParameterListener;
    arguments:
    – location

    tags:
    – { name: kernel.event_listener, event: oro_datagrid.datagrid.build.after.webmuch-search-grid, method: onBuildAfter }

    advancesearchprocess.html

    {% extends ‘OroUIBundle:actions:index.html.twig’ %}
    {% import ‘OroUIBundle::macros.html.twig’ as UI %}
    {% import ‘OroDataGridBundle::macros.html.twig’ as dataGrid %}
    {% set gridName = ‘webmuch-search-grid’ %}
    {% set params = {location: loc} %}

    datagrid.yml

    webmuch-search-grid:
    source:
    type: orm
    query:
    select:
    – j.name
    – l.amountOfLoan
    – j.state
    – l.loanStatus

    from:
    – { table: GroupBundle:MemberDetails, alias: j }
    join:
    left:
    – { join: j.loan, alias: l}
    where:
    and:
    – j.city = :location

    columns:
    name:
    label: Name
    amountOfLoan:
    label: Principal
    state:
    label: State
    loanStatus:
    label: Status
    date:
    label: date
    frontend_type: datetime

    sorters:
    columns:
    name: { data_name: j.name }
    amountOfLoan: { data_name: l.amountOfLoan }
    state: { data_name: j.state}
    loanStatus: { data_name: l.loanStatus}

    filters:
    columns:
    name:
    type: string
    data_name: j.name
    amountOfLoan:
    type: number
    data_name: l.amountOfLoan
    state:
    type: string
    data_name: j.state
    loanStatus:
    type: string
    data_name: l.loanStatus

    options:
    entityHint: Member Details
    export:
    csv: { label: oro.grid.export.csv }

    My Custom EventListener Looks like

    class ParameterListener
    {
    protected $parameterName;
    protected $requestParameterName;

    public function __construct($parameterName, $requestParameterName = null)
    {
    $this->parameterName = $parameterName;
    $this->requestParameterName = $requestParameterName ? $requestParameterName : $this->parameterName;
    }

    public function onBuildAfter(BuildAfter $event)
    {
    $datagrid = $event->getDatagrid();
    $datasource = $datagrid->getDatasource();
    $parameters = $datagrid->getParameters();

    if ($datasource instanceof OrmDatasource) {
    /** @var QueryBuilder $query */
    $queryBuilder = $datasource->getQueryBuilder();

    $queryBuilder->setParameter($this->parameterName, $parameters->get($this->requestParameterName));
    }
    }
    }

    But I’ve this error :

    An exception has been thrown during the rendering of a template (“Invalid parameter number: number of bound variables does not match number of tokens”) in OroUIBundle:actions:index.html.twig at line 28.

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #6347

    Alexandr Smaga
    Participant

    Hello!

    It says that the number of params passed to query is not enough for it execution. It’s might be related to cache, did you try to clear cache after listener is registered ?

    Also did you aware about new datagrid parameter bindings that was introduced in 1.4 RC ?

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.