OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums OroCRM OroCRM – Programming Questions Sorter For Dynamic DataGrid

This topic contains 8 replies, has 3 voices, and was last updated by  a.azadi 10 months, 1 week ago.

  • Creator
    Topic
  • #37885

    a.azadi
    Participant

    Hi everyone. I wanted to write a sorter for a datagrid which is getting its columns and data from a listener.
    This is my two methods in my listener class.
    I want to know how to make sorter for these columns.
    Also during searching I found out a method in “DatagridConfiguration” called “addSorter”. But I don’t know how to use it IF it’s gonna work for adding sorter to our columns.

    Thank You,
    Aryana.

    • This topic was modified 10 months, 3 weeks ago by  a.azadi.
    • This topic was modified 10 months, 3 weeks ago by  a.azadi.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
    Replies
  • #37890

    Hello, a.azadi.

    It depends on the way you work with datasource.

    If you have modified original datasource (e.g. by adding new select and/or join parts) and it is in fact presented in DB then you may add a sorter for it. Have a look at the example – here listener adds a new sorter for a column that was added previously in the same listener. offsetSetByPath method is used here, but addSorter can be used as well – addSorter is just a shortcut for this kind of operations.

    If you haven’t modified your datasource and just mixing the data using separate query or any other source then standard out of the box sorters will not work for you, unfortunately.

    #37928

    a.azadi
    Participant

    Thank you for your answer and help. I wrote this line of code after the addColumn method line:

    It adds the sorter but sorters won’t work at all. No response when I use sorter on any column.
    I tried to debug and try some other things but could not find a solution.
    Do you have any idea about the problem here?

    Thank You Again,
    Aryana.

    #37931

    Hello Aryana.

    It does not work because main datagrid query is not aware about these columns, so you have no result.

    Standard grid uses one main query to get data, filter data and sort data – so, default filters and sorter work on this query. In your case main query remained untouched – it doesn’t have columns for group names as group name in your case is just a label, not a field in the query.

    When you are working with grid you are not using main query – instead you have created new additional query ($qb = $this->em->getRepository(“WebSysVisitBundle:Visit”)…) to get groups and manually applied filters. That is why main query is not aware about your groups and sorters do not work.

    If you want to fix it you may add new join for each found group and then set required query column to each sorter.

    #37978

    a.azadi
    Participant

    Hello Yehven.

    Unfortunately I did not understand your solution. I asked some of my friends and they could not understand this fix too: ” If you want to fix it you may add new join for each found group and then set required query column to each sorter. ”
    Can you please tell me more about it?

    Thank you a lot.

    • This reply was modified 10 months, 2 weeks ago by  a.azadi.
    #37985

    Imagine you have some main entity e.g. Customer and then you can show a filterable/sortable column for each associated Group. You have 3 groups with IDs 1, 2 and 3.

    To do that you have to join Group entity three times like that:

    By doing that you now can work with three separate joins/aliases and create filter/sorter for each of them.

    Of course, this is just a demonstration of the approach, but using it you may have a new column for each group, select some column and then add a filter a sorted using these new relations.

    #37987

    a.azadi
    Participant

    I have some columns which I’m getting from this query:

    Now, my result is not static. It’s dynamic based on the data in the database I’m using. It may get 10 rows from the database or it may get only one.
    So my columns varies between maybe 1 to 20 columns.
    I tried to add select to my query like this:

    I got exception which I think is obvious because $group[‘groupName’] is not a class. It’s a string and it’s exactly my column name which I want to use sort and filter on.

    And this in my datagrid:

    I guess I can’t use your solution or maybe I misunderstood your solution.

    I hope I could have been explain my problem a little better. I appreciate your help and sorry if I have problem in speaking English.

    Aryana.

    • This reply was modified 10 months, 2 weeks ago by  a.azadi.
    #37990
    Michael
    Michael
    Keymaster

    Hi Aryana,

    Let me kinda “re-start” this thread from a different point.

    If I understood the code you posted correctly, you want to add multiple columns to this grid. For example, if there are 20 different contact groups – then this grid will 20 additional columns, so that there will be 22 columns:
    visitorName, orgName, groupName1, groupName2, groupName3, groupName4, groupName5, groupName6, groupName7, groupName8, groupName9, groupName10, groupName11, groupName12, groupName13, groupName14, groupName15, groupName16, groupName17, groupName18, groupName19, groupName20
    , and each row in this grid will have 22 cells.

    What should be displayed inside those additional 20 cells in each row?

    #38050

    a.azadi
    Participant

    Hi Michael,

    Yeah it’s correct.

    This is my onResultAfter Code:

    Getting the data from the query and adding it to my datagrid.

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

You must be logged in to reply to this topic.

You will be redirected to [title]. Would you like to continue?

Yes No