Primefaces lazytable sorting change first sorting order - sorting

is there any way to allow, after the first request to sort a particular column, not to be listed first in ascending order, but first in descending order?
description:
If I need to sort the column in descending order, it is necessary to first click on the column in ascending order and only then reload the table with the sorted data as I require.
One not entirely nice solution that I use now is in the case of columns, where I require the reverse order, I simply swap the meaning ascending/descending when querying the DB. But the table does not show graphically correctly the arrow above the table in which direction I am sorting the data and it is necessary to intervene for the columns in CSS.
Is there a more elegant option?
Sorry for my easy English and thanks for any advice,
Venca.

As #Melloware pointed in comment datatable has fields sortBy and sortOrder which can be used for sorting.
See example:
<p:dataTable id="txnTable"
value="#{chTransactionsForm.transactions}" var="res"
sortMode="single" sortBy="#{res.activityDate}" sortOrder="DESCENDING"
rows="#{referenceData.recordsPerPage}" rowKey="#{res._lineNumber}"
lazy="true" resizableColumns="true"
paginator="true" paginatorPosition="bottom" paginatorAlwaysVisible="false"
paginatorTemplate="#{referenceData.paginatorTemplate}">
<p:column id="activityDate" headerText="#{msg.transDate}"
sortBy="#{res.activityDate}" width="120">
<h:outputText value="#{res.activityDate}">
<f:convertDateTime timeZone="#{referenceData.timezone}"
pattern="MMM dd, yyyy HH:mm" />
</h:outputText>
</p:column>
...

Related

PrimeNG datatable performance very slow in case there is a lot of data

I use PrimeNG datatable. In case the table contains many rows, the datatable's performance works very slow.
This is my html:
<p-dataTable #dt [rowTrackBy]="rowTrackBy" [emptyMessage]="'TABLE.EMPTY_MESSAGE'|translate" #dt [rows]="rows" [paginator]="paginator"
lazy="false" [pageLinks]="3" scrollable="true"[editable]="editable" [styleClass]="paginator?'paginator': enableFilter?'scroll filter-table':'scroll'"
[globalFilter]="gb"[value]="displayList" resizableColumns="true" [(selection)]="selectedItem"
(onRowDblclick)="importButton?'':onRowDblclick($event.data)"[expandableRows]="showExpander" [expandedRows]="expandedRows"
(onRowSelect)="onrowSelect($event)" (onRowClick)="selectRow($event);onrowSelect($event)" (onRowUnselect)="onRowUnSelect($event)"[rowStyleClass]="rowStyleClass"
[selectionMode]="(enableSelect&&!showSelectColumn)?(multiSelect?'multiple':'single'):''" [metaKeySelection]="false"
(onHeaderCheckboxToggle)="onHeaderCheckboxToggle($event)">

CAML Query to return all row ID's where Date expires is less then Date Completed

I need a CAML Query for SP that Compares the Date expires and date Completed and returns all row ID's where the condition is true.
I then have a count set up that will count the items in the collection variable and set that to a new variable then the variable is used to update a status page. Please Help been at this for days and cant seem to figure it out. Below is the code I currently have that's not working. The Query below seems to compare the Date expires with the current items date completed I want to look at each row and compare them separately, if date expires is less then date completed return ID. Thank you guys for any assistance.
<Query>
<Lists>
<List ID="{my-list-id}" />
</Lists>
<ViewFields>
<FieldRef Name="ID" />
</ViewFields>
<Where>
<And>
<And>
<Eq>
<FieldRef Name="Status" />
<Value Type="Choice">Closed</Value>
</Eq>
<Eq>
<FieldRef Name="twoDigTskYr" />
<Value Type="Number">18</Value>
</Eq>
</And>
<Gt>
<FieldRef Name="DateExpires" />
<Value Type="DateTime">{ItemProperty:Date_x0020_Completed}</Value>
</Gt>
</And>
</Where>
<ViewAttributes Scope="Recursive" />
</Query>
You cannot compare two fields with a CAML query. One workaround is to add a calculated field to your list which does the comparison, because you can filter on a calculated field in CAML.

sortBy an EL Expression in primefaces

Is it possible to use sortBy with an EL expression containing multiple values in Primefaces , if it is how or how can i approach this.
Problem:
I Need to sory the table by latest date. There are two columns one with created date and another with updated date. if updated exist i need to use it to sort.
I looked at JSF 2 , Primefaces 4.0. p:dataTable sorting using complex sortBy expression
and PrimeFaces dataTable sorting not working but neither does what i need. second one was just in google search
Example
<p:column headerText="Last Logged in Date" sortBy="#{login.lastUpdated ne null ? login.lastUpdated : login.createdDate }">
<h:outputText value="#{login.lastUpdated ne null ? login.lastUpdated : login.createdDate }" >
<f:convertDateTime pattern="yyyy/MM/dd HH:mm" />
</h:outputText>
</p:column>
Any Advice would be appreciated.
Thanks in advance.

Sorting rich:dataTable with second value in a column

I have a rich dataTable that has a column which contains the full name of a person (Last name, first Name). I currently have the table so that the columns can be sorted based on the last name of the person. However I want it so that if the last names are equal it will then sort by the first names next. Is this possible? How can I do it?
<rich:column sortBy="#{list.lastName}">
<h:outputLabel value="#{list.lastName} #{list.firstName}"/>
</rich:column>
Example:
If the names were (B Smith and A Smith)
Should be sorted:
Smith A
Smith B
That isn't possible with <rich:dataTable>.
You'd better add a (transient) getter which returns the "full name":
#Transient // Only if it's a JPA entity.
public String getFullName() {
return lastName + " " + firstName;
}
And then use it in sorting:
<rich:column sortBy="#{list.fullName}">

Grouping and Sorting in RadGid

I have a issue need to resolve.
How to group Data on Radgrid but no sort. Radgri only group, no sort. Because if Radgrid sort , data will incorrect
Please help me to resolve it
Thank all so much
Set the allowsorting property to false.
<telerik:radgrid id="RadGrid1" runat="server" allowsorting="False">
Also, if you need to know how to group data, use a GridCalculatedColumn:
<telerik:GridCalculatedColumn UniqueName="Name" HeaderText="Name"
DataFields="FirstName, LastName"
Expression="{0} + ' ' + {1}">
</telerik:GridCalculatedColumn>

Resources