Message Boards
Question to Filtering and Sorting Items with the Management Toolbar
Reiner Zufall, modified 3 Years ago.
Question to Filtering and Sorting Items with the Management Toolbar
New Member Posts: 22 Join Date: 7/6/20 Recent Posts
Hello there
i am trying to implement clay management tool bar. I use this reference https://help.liferay.com/hc/en-us/articles/360017886172-Filtering-and-Sorting-Items-with-the-Management-Toolbar-
with searchcontainer
but i don't understand the example code.
i dont understand the varibale within the constructor.
MyManagementToolbarDisplayContext object.
i am trying to implement clay management tool bar. I use this reference https://help.liferay.com/hc/en-us/articles/360017886172-Filtering-and-Sorting-Items-with-the-Management-Toolbar-
with searchcontainer
but i don't understand the example code.
i dont understand the varibale within the constructor.
[code] LiferayPortletRequest liferayPortletRequest,
LiferayPortletResponse liferayPortletResponse,
HttpServletRequest request,
SearchContainer searchContainer
How to create these and pass them toMyManagementToolbarDisplayContext object.
Andre Kreienbring, modified 3 Years ago.
RE: Question to Filtering and Sorting Items with the Management Toolbar
Regular Member Posts: 152 Join Date: 12/18/06 Recent Posts
Basically you need to create a SearchContainer and optionally (recommended) a DisplayContext.
I do it like this:
Create the Searcontainer in the render phase of the MVC Portlet module and put it in the request:
I do it like this:
Create the Searcontainer in the render phase of the MVC Portlet module and put it in the request:
PortletURL iteratorURL = PortletURLUtil.getCurrent(renderRequest, renderResponse);
_deviceDisplaySearchContainer = new SearchContainer<devicedisplay>(renderRequest, iteratorURL, null, "nothing found");
</devicedisplay>
Then in the JSP:<%
SearchContainer<devicedisplay> deviceDisplaySearchContainer = (SearchContainer<devicedisplay>) request.getAttribute("deviceDisplaySearchContainer");
[My]ManagementToolbarDisplayContext [my]ManagementToolbarDisplayContext = new [My]ManagementToolbarDisplayContext(request, liferayPortletRequest, liferayPortletResponse, deviceDisplaySearchContainer);
%>
</devicedisplay></devicedisplay>
If you create the ManagementToolbar like this:<clay:management-toolbar displayContext="<%= [my]ManagementToolbarDisplayContext %>" />
You'll be able to access the Parameters from the ManagementToolbar in the methods of the DisplayContext. The Toolbar calls methods like @Override
protected String getNavigation() {
String navigation = ParamUtil.getString(liferayPortletRequest, getNavigationParam(), "all");
String orderByType = ParamUtil.getString(liferayPortletRequest, getOrderByTypeParam(), "asc");
String orderByCol = ParamUtil.getString(liferayPortletRequest, getOrderByColParam(), "[myDefaultOrder]");
String keywords = ParamUtil.getString(liferayPortletRequest, "keywords", null);
String displayStyle = ParamUtil.getString(liferayPortletRequest, "displayStyle", getDefaultDisplayStyle());
}
for filtering and @Override
public String getSortingOrder() {
String orderByType = ParamUtil.getString(liferayPortletRequest, getOrderByTypeParam(), "asc");
String orderByCol = ParamUtil.getString(liferayPortletRequest, getOrderByColParam(), "[myDefaultOrder]");
}
for sorting.
Reiner Zufall, modified 3 Years ago.
RE: Question to Filtering and Sorting Items with the Management Toolbar
New Member Posts: 22 Join Date: 7/6/20 Recent Posts
thank you so much, you really helped me
but i have a few more question
do i have to override methods in "MyManagementToolbarDisplayContext" to make changes happend like ordering "asc" or "desc". And how do i know which method i have to override?
i use searchContainer tag in my .jsp file to display the grid. How can i change the display of the grid depending on the selected option i choose in clay management toolbar to e.g "filter by name"?
An i have a question to this code snippet. sry but i don't understand how to use this related to clay management toolbar and what is the return type of this method?
And my last question, in clay management tool i have a tag named "getSortingURL" for what do i need this
but i have a few more question
do i have to override methods in "MyManagementToolbarDisplayContext" to make changes happend like ordering "asc" or "desc". And how do i know which method i have to override?
i use searchContainer tag in my .jsp file to display the grid. How can i change the display of the grid depending on the selected option i choose in clay management toolbar to e.g "filter by name"?
|
|
|
|
|
|
|
}
An i have a question to this code snippet. sry but i don't understand how to use this related to clay management toolbar and what is the return type of this method?
And my last question, in clay management tool i have a tag named "getSortingURL" for what do i need this
Andre Kreienbring, modified 3 Years ago.
RE: Question to Filtering and Sorting Items with the Management Toolbar
Regular Member Posts: 152 Join Date: 12/18/06 Recent Posts
To 1: The best you can do is to look into the Liferay source code:
Your DixplayContext most likely extends "SearchContainerManagementToolbarDisplayContext" and that extends "BaseManagementToolbarDisplayContext". Find the methods you can override in these classes.
getSortingURL() is also defined there.
In getNavigation(): Look at the parameters that are passed from the ManagementToolbar and use the [My]LocalServiceUtil (created by Service Builder) to get your entities. Finally put the results in the SearchContainer.
Example:
Your DixplayContext most likely extends "SearchContainerManagementToolbarDisplayContext" and that extends "BaseManagementToolbarDisplayContext". Find the methods you can override in these classes.
getSortingURL() is also defined there.
In getNavigation(): Look at the parameters that are passed from the ManagementToolbar and use the [My]LocalServiceUtil (created by Service Builder) to get your entities. Finally put the results in the SearchContainer.
Example:
_mySearchContainer.setTotal(_myList.size());
_mySearchContainer.setResults(_myList);
Reiner Zufall, modified 3 Years ago.
RE: Question to Filtering and Sorting Items with the Management Toolbar
New Member Posts: 22 Join Date: 7/6/20 Recent Posts
Thank you so much
i tried to sort the grid. But when i get the Params from the clay management toolbar, the sorting order is always "asc".
in MyManagementToolbarDisplayContext.java i have overwritten the getSortingOrder as follow
But everytime i refresh the site or press on the "sorting direction" button in clay management toolbar, i always get the output
how can i pass the current value to .jsp?
i tried to sort the grid. But when i get the Params from the clay management toolbar, the sorting order is always "asc".
in MyManagementToolbarDisplayContext.java i have overwritten the getSortingOrder as follow
@Override
public String getSortingOrder() {
String orderByType = ParamUtil.getString(liferayPortletRequest, getOrderByTypeParam(), "desc");
//String orderByCol = ParamUtil.getString(liferayPortletRequest, getOrderByColParam());
if(orderByType.equals("asc")) {
orderByType="desc";
System.out.println("equals asc");
}else if(orderByType.equals("desc")){
orderByType="asc";
System.out.println("equals desc");
}else {
orderByType="desc";
}
if(Validator.isNull(orderByType)) {
orderByType = "desc";
}
System.out.println(" orderByType " + orderByType);
return orderByType;
}
But everytime i refresh the site or press on the "sorting direction" button in clay management toolbar, i always get the output
System.out.println("equals asc");
how can i pass the current value to .jsp?
Andre Kreienbring, modified 3 Years ago.
RE: Question to Filtering and Sorting Items with the Management Toolbar
Regular Member Posts: 152 Join Date: 12/18/06 Recent Posts
For me it works like this:
When getNavigation() is called I fill my List accordingly to the set filter. The List is like:
BTW: If someone can please explain why we need to set the Comparator on the SearchContainer AND sort the List manually. Maybe there's a more efficient way to achive the sorting...
When getNavigation() is called I fill my List accordingly to the set filter. The List is like:
List<mydisplay> myEntities = new ArrayList<mydisplay>();
</mydisplay></mydisplay>
When getSortOrder() is called I do: mySearchContainer.setOrderByCol(orderByCol);
mySearchContainer.setOrderByType(orderByType);
mySearchContainer.setOrderByComparator(comparator);
myEntities.sort(comparator);
For this you'll need a Comparator that sorts your entities. And as far as I understand it, the asc / desc setting comes from the Comparator.BTW: If someone can please explain why we need to set the Comparator on the SearchContainer AND sort the List manually. Maybe there's a more efficient way to achive the sorting...
Reiner Zufall, modified 3 Years ago.
RE: Question to Filtering and Sorting Items with the Management Toolbar
New Member Posts: 22 Join Date: 7/6/20 Recent Posts
Thank you for your answer.
I got the asc/desc order by creating a Comparator object like this:
and in searchcontainer tag i user LocalserviceUtil as follow:
In ManagementToolbarDisplay i got the methods which i get the column name and asc and desc String.
in jsp i switch the boolean var depending on the value i got from ManagementToolbarDisplay.
I have an other question, when i got the Filter name returned by getNavigator, how i know which column i have to choose. When i use
and should i create get-Methods in -service to find the columns?
I got the asc/desc order by creating a Comparator object like this:
boolean asc = false;
OrderByComparator<entityname> obc = OrderByComparatorFactoryUtil.create("EntityName",columnName,asc);</entityname>
and in searchcontainer tag i user LocalserviceUtil as follow:
<... results="<%=LocalServiceUtil.getEnties(searchContainer.getStart(), searchContainer.getEnd(), obc)%>"/>
In ManagementToolbarDisplay i got the methods which i get the column name and asc and desc String.
in jsp i switch the boolean var depending on the value i got from ManagementToolbarDisplay.
I have an other question, when i got the Filter name returned by getNavigator, how i know which column i have to choose. When i use
String orderByCol ParamUtil.getString(liferayPortletRequest, getOrderByColParam(), "[myDefaultOrder]");
twice, i cannot open the Clay managementToolbar dropdown Menu.and should i create get-Methods in -service to find the columns?
Andre Kreienbring, modified 3 Years ago.
RE: Question to Filtering and Sorting Items with the Management Toolbar
Regular Member Posts: 152 Join Date: 12/18/06 Recent Posts
You can get the "navigation" from the request URL with
String navigation = ParamUtil.getString(liferayPortletRequest, getNavigationParam(), "all");
And of course you need to react on the filter and implement it somehow. [YourEntitiy]LocalServiceImpl may be a good place for the implementation. If you have your filtered List ready just do: searchcontainer.setResults(List<YourEntity>) again.
Reiner Zufall, modified 3 Years ago.
RE: Question to Filtering and Sorting Items with the Management Toolbar
New Member Posts: 22 Join Date: 7/6/20 Recent Posts
yes i did the navigation on the same way.
My filter and sorting function work.
Thank you so much
My filter and sorting function work.
Thank you so much