cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper II
Helper II

Sort sharepoint datatable

Hi!

 

I've got sharepoint list, which is source for DataTable in my PowerApps app. I've used Item property (in DataTable) to create filters for my DataTable (ex. 

If (((Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit),
Filter(SharePointListSource, ColumnName=Dropdown2_3.Selected.Result)

etc.)

So, that's working fine. 

 

But I've got no clue how to create and add "Sort by date" button. Which be sorting my DataTable by Date(or any other column in DataTable) in all cases, descending/ascending/while being filtered.

Could you help me with this one?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @nottheOther ,

Could you please share a bit more about your scenario?

Do you want to sort your Data Table records based on the selected column name () from the Dropdown box?

 

I have made a test on my side, please consider take a try with the following workaround:

1. Add a Dropdown control in your app, set the Items property to following:

["date", "ID", "Status", ...]    // Specify the availble columns from your data source here

Note: Currently, the SortByColumns function could not be used to sort by a complex type column, e.g. LookUp, Choice, Person, etc.

2. Set the Items property of the Data Table to following:

If(
    Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
    If(
      Dropdown1.Selected.Value = "date",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), date, Descending),
      Dropdown1.Selected.Value = "ID",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), ID, Descending),
      Dropdown1.Selected.Value = "Status",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), Status, Descending),
      ...
      ...
    )
)

If the Status is a Choice type column in your SP list, please consider modify above formula as below:

If(
    Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
    If(
      Dropdown1.Selected.Value = "date",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), date, Descending),
      Dropdown1.Selected.Value = "ID",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), ID, Descending),
      Dropdown1.Selected.Value = "Status",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), Status.Value, Descending),   // Modify formula here
      ...
      ...,
      )
)

 

In addition, you could also consider create each button for these columns you want to sort by in your app, then set the OnSelect property of the "sort by date" button to following:

Set(SortColumn, "date")

set the OnSelect property of the "sort by ID" button to following:

Set(SortColumn, "ID")

set the OnSelect property of the "sort by Status" button to following:

Set(SortColumn, "Status")

 

Then set the Items property of the Data Table to following:

If(
    Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
    If(
      SortColumn = "date",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), date, Descending),
      SortColumn  = "ID",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), ID, Descending),
      SortColumn  = "Status",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), Status, Descending),
      ...
      ...,
      Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result) // If SortColumn variable is blank, do not sort your data table
      )
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Dual Super User III
Dual Super User III

Hey @nottheOther 

 

You can set the configuration as:

Button to Sort -> OnSelect -> Set(SortOrder,!SortOrder)

DataTable -> Items -> If (Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
Sort(Filter(SharePointListSource, ColumnName=Dropdown2_3.Selected.Result),DateColumnName, If(SortOrder,"Ascending","Descending")))

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Hi,

 

but in this case the only option for sorting is by Date column? Is there an option which I create few buttons/or dropdown list with other columns name for sorting? Ex.

- sort by date - DateColumnName

- sort by ID - IDColumnName

- sort by Status - StatusColumnName

etc. you get the idea.

Your solution give me only option for DateColumn. Maybe setting a variable?

Hi @nottheOther ,

Could you please share a bit more about your scenario?

Do you want to sort your Data Table records based on the selected column name () from the Dropdown box?

 

I have made a test on my side, please consider take a try with the following workaround:

1. Add a Dropdown control in your app, set the Items property to following:

["date", "ID", "Status", ...]    // Specify the availble columns from your data source here

Note: Currently, the SortByColumns function could not be used to sort by a complex type column, e.g. LookUp, Choice, Person, etc.

2. Set the Items property of the Data Table to following:

If(
    Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
    If(
      Dropdown1.Selected.Value = "date",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), date, Descending),
      Dropdown1.Selected.Value = "ID",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), ID, Descending),
      Dropdown1.Selected.Value = "Status",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), Status, Descending),
      ...
      ...
    )
)

If the Status is a Choice type column in your SP list, please consider modify above formula as below:

If(
    Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
    If(
      Dropdown1.Selected.Value = "date",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), date, Descending),
      Dropdown1.Selected.Value = "ID",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), ID, Descending),
      Dropdown1.Selected.Value = "Status",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), Status.Value, Descending),   // Modify formula here
      ...
      ...,
      )
)

 

In addition, you could also consider create each button for these columns you want to sort by in your app, then set the OnSelect property of the "sort by date" button to following:

Set(SortColumn, "date")

set the OnSelect property of the "sort by ID" button to following:

Set(SortColumn, "ID")

set the OnSelect property of the "sort by Status" button to following:

Set(SortColumn, "Status")

 

Then set the Items property of the Data Table to following:

If(
    Dropdown2_2.DisplayMode = Disabled && Dropdown2_3.DisplayMode = Edit,
    If(
      SortColumn = "date",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), date, Descending),
      SortColumn  = "ID",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), ID, Descending),
      SortColumn  = "Status",
      Sort(Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result), Status, Descending),
      ...
      ...,
      Filter(SharePointListSource, ColumnName = Dropdown2_3.Selected.Result) // If SortColumn variable is blank, do not sort your data table
      )
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (8,419)