cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
nottheOther
Level: Powered On

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

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

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!

nottheOther
Level: Powered On

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?

Community Support Team
Community Support Team

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
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (6,737)