ssossossosso

Forums

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

Open-Source CRM software Forums OroPlatform OroPlatform – Programming Questions get checked item IDs from datagrid in widget

This topic contains 7 replies, has 2 voices, and was last updated by  jakabadambalazs 2 years, 1 month ago.

  • Creator
    Topic
  • #8105

    jakabadambalazs
    Participant

    Hi,

    I have a dialog widget which opens and renders a datagrid with editable checkboxes for each row. I’d like to send the id of each checked item to some controller action:

    the dialog widget content:

    datagrid extract:

    as you can see I did not have a form type just a plain form tag, so I need to intercept the submit action serialize the list of ids in some hidden field and send it to the controller.

    can it be done this way by using some js or would it be better to build a form?

    thanks
    a\


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

Viewing 7 replies - 1 through 7 (of 7 total)
  • Author
    Replies
  • #8112
    Yevhen Shyshkin
    Yevhen Shyshkin
    Oro Core

    Hello.

    There are two ways to do that out of the box:

    1) you can use mass actions, see examples on contact grid (delete action) and accounts grid (merge action);

    2) you can use existing hidden form type for such boolean fields, see User Group edit page, field “Has group”.

    #8142

    jakabadambalazs
    Participant

    Hi yshyshkin,

    Thanks I have read some docs and I actually opted for the solution you used when assigning accounts for Contacts. And I am nearly there – I have one little problem to resolve.

    I created a form with two unmapped fields:

    My controller action is calling the form handler and successfully intercepts the ‘appendElements’ and ‘removeElements’ form data and does what it has to do.

    This is my dialog widget:

    When I click the save button it triggers the controller action, data is persisted, messenger shows my message, underlying datagrid in the page is refreshed and the dialog closes.

    All is perfect, except for one thing.
    If I hit the “select” button which reopens the dialog, the datagrid in the dialog is not up to date (the checkboxes do not reflect the persisted changes). If I hit the datagrid’s refresh button it reloads the datagrid and now persisted changes are visible.
    So I tried to add

    in my code before closing the dialog to force refresh the datagrid but no changes.

    Any ideas?
    thanks
    a\


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #8143
    Yevhen Shyshkin
    Yevhen Shyshkin
    Oro Core

    I think you should reload grid not before closing but after opening because widget data is destroyed after dialog closed.

    You are using event “datagrid:doRefresh:” – that’s correct. Please, try to run it after grid loaded – f.e. using event “grid_render:complete” for your specific grid.

    Another solution – you can find out where outdated data came from and clear this data. Possible place – Oro/Bundle/DataGridBundle/Resources/public/js/content-manager.js.

    #8148

    jakabadambalazs
    Participant

    Thanks, Tomorrow I’ll try.

    I know how to do the first one (probably). I actually realized that the datagrid was not even present when I was trying to reload it (because it is only rendered when the ‘save’ variable is false). 😉

    But no clue about the second (event though I think it would be best) – I looked into at contentManager and I can see it has two methods: get and trace. What do I do? Do I just use the get method (which returns a collection object) and just set the returned collection to null?

    a\


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #8166

    jakabadambalazs
    Participant

    Sweet! I hooked into ‘oronavigation/js/content-manager’ and I clean up the cached datagrid data before closing my dialog widget this way:

    It works well! It is a bit different from how you suggested. Is it dirty or can I leave it like this?

    thanks
    a\


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

    #8171
    Yevhen Shyshkin
    Yevhen Shyshkin
    Oro Core

    I don’t see any major issues here, so you can leave it.

    Accidently I’ve found another solution – you can initialize widget with “reload-grid-name” option and this grid will be automatically refreshed with widget reloading – you can also try this one.

    #8176

    jakabadambalazs
    Participant

    Thanks! but I don’t think in this case it is of use:
    I have this button to open the dialog:

    I already have a ‘reload-widget-name’ under the widget section which reloads the datagrid in the page when i trigger the “widget_success:wid” (mediator.trigger(‘widget_success:’ + widget.getWid());) from the dialog. and it works ok – my problem is/was with the datagrid inside the dialog widget.

    thanks a lot
    a\


    oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.