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

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
Highlighted
Community Support
Community Support

Re: Sort sharepoint datatable

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
Highlighted
Dual Super User III
Dual Super User III

Re: Sort sharepoint datatable

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!

Highlighted
Helper I
Helper I

Re: Sort sharepoint datatable

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?

Highlighted
Community Support
Community Support

Re: Sort sharepoint datatable

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
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (9,063)