-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intent to Implement: amp-sort #8691
Comments
Nice—excited to see this handling a broad case Looks like filtering would be fairly straightforward to add on to this, using a similar model. Is that a fair assumption? That is, would amp-filter (or however it might end up getting implemented) be able to take advantage of the same structure of data-* attributes to filter on, or would it need a different approach? |
@ericlindley-g |
/cc @sebastianbenz |
@aghassemi This looks great. Couple notes/questions:
We'd need to document clearly that we do not do initial reshuffling, right? In other words, if it says
The default value is often sensitive to value type. E.g. strings default to "asc" and numbers "desc". Maybe we can come up with some coding for this to leave it to the page author? E.g.
I assume, we'd never need something like |
Yes, no initial sorting however there is no requirement that initial order matches
Good point. I like the format you have, reads nicely too "toggle or descending"
We probably need to support compound sorting to allow breaking ties in meaningful ways maybe: |
As it is developed, the documentation page is able to be previewed here: https://dereklewis.github.io/amp-docs/docs/reference/components/amp-sort/ Anticipated completion: prior to the Q2 mid-quarter roadmap update. |
This issue hasn't been updated in awhile. @aghassemi Do you have any updates? |
The rest of the code is on my drive in my apartment out of state. I will be returning in December, at which point I will be making the PR. My apologies for the delay; thanks for your patience! |
Hi we are working on a couple of retail sites - this is a blocker for us. Currently we are doing a lot of engineering server side- would love this feature- as it means we can launch a lot quicker. |
/cc @lswang1618 @dereklewis we need to prioritize this for e-commerce. Would you be able to send a PR with your work in progress? |
Yes, I'll get that WIP PR in today. My apologies for the delay, unfortunately life showed up for me. |
back to P2 after chatting with @lswang1618 |
FYI got several requests for this and amp-filter at the AMP roadshow today, and a few folks who are also interested in helping out that may jump in on the thread. |
Birthday celebrations prevented me from getting to this as I would have liked. @ericlindley-g, it would be great if you could find someone to take care of the unit tests for these components (the more the merrier). Additionally, I am currently in a situation where I have a conflict of interest in making contributions to Google open-source code bases. I give @aghassemi permission to be the sole owner of this component. Feel free to copy and paste all of the code verbatim, no attribution necessary. |
Great work on what you are doing all ! If you can clearly let us know what things you looking for help with ( both beginners tasks, intermediate and advanced then I am sure there are users that would help share the load) |
@dereklewis thanks for your work on this. Given you are no longer working on the component, we will start from scratch to turn my prototype (https://github.com/aghassemi/amphtml/blob/filtersort-proto1/extensions/amp-sort/0.1/amp-sort.js) into a component. |
This issue hasn't been updated in awhile. @aghassemi Do you have any updates? |
No longer planning to launch this component since the use-case can be handle via |
@aghassemi could you elaborate how I can use the mentioned components to sort a table in place without having a "dynmic" list source? ie.: I have a table, and I want the rows of the table sorted without having to make calls to an endpoint that will return JSON data. |
@stylesuxx You would still need to use See https://ampbyexample.com/dynamic_amp/client-side%20filtering/ for an example, although it initially loads the data from remote end point in this example, filtering is done all using local data. |
@aghassemi great - thank you very much. Not sure how I missed that. |
@aghassemi I have to come back to you: |
@stylesuxx Initial render from It's definitely more work than having an |
Background
sortable tables - #6057 outlines a design by @derekcecillewis for supporting sortable tables in AMP.
amp-sort
is a proposal to bundle most of the concepts from thesortable tables
into a generic client-side sorting component that can support tables as well as lists and other arbitrary DOMs.Proposal
amp-sort
is a functional AMP extension that can rearrange a subset of its descendants by comparing values of HTML attributes which are present on the descendants.Simple Example
Demos
Following page has 3 working demos of
amp-sort
https://amp-sort.firebaseapp.com/test/manual/amp-sort.amp.html
Behaviour
amp-sort
can contain any other HTML or AMP element (including nestedamp-sort
)amp-sort
performs the following actions when.sort()
is called:attribute
specified bysort-by
value-type
sort-direction
sorted
,sorted-by=<sort-by value>
,sorted-by=<sort-direction value>
to theamp-sort
component so CSS can be used to target the sorted items (e.g. hide/show sorted UI indicators, etc...)amp-sort
works with and withoutamp-bind
.Detailed API
Attributes
sort-by
The name of the attribute on descendants which its value is used for sorting comparison.
sort-by
is bindable viaamp-bind
and triggers a resort when changed.sort-direction
One of
asc
,desc
,toggle
. Defaults toasc
.asc
ordesc
specify if sorting should be in ascending or descending order.toggle
will reverse the previously used sort direction.sort-direction
is bindable viaamp-bind
and triggers a resort when changed.value-type
One of
string
,number
. Defaults tostring
.Specifies the data-type of the values of the attribute specified by
sort-by
.value-type
is bindable viaamp-bind
and triggers a resort when changed.Actions
sort([sortBy:<attr>], [sortDirection:<dir>], [valueType=<type>])
Calling
sort()
action onamp-sort
will trigger sorting. Optionally new sorting configuration can be provided to override existing configuration attributes.Complex Examples
Multiple Sort Fields
without amp-bind
with amp-bind
Sorting Tables
Sorting tables is not fundamentally different than the examples above however the UX
of sortable tables normally involves having column headers
toggle
sort direction and there isusually visible sort indicators on sorted columns.
HTML
CSS
As mentioned in the Behaviour section,
amp-sort
addssorted
,sorted-by=<sort-by value>
,sorted-by=<sort-direction value>
to theamp-sort
component so CSS can be used to target the sorted items. We will take advantages of that here:A11Y Considerations
amp-sort
actually moves the DOM elements upon sorting so DOM order will correctly represent thevisual order. (As opposed to using CSSorder
property which does not reorder the actual DOM and is not supported by almost all screen readers).amp-sort
detects tables and additionally addsaria-sort
property on the table header.Performance Considetations
sort-by
andsort-direction
), actual sorting only happens once and not be config change. This is because:amp-bind
already handles batching and only triggers a mutation once when multiple states are change synchronously together.sort()
action optionally takes all the configuration so multiple config changes can be bundled with a single call tosort()
amp-sort
to ensure only a single browser relayout/paint to happen after all DOM elements have been moved. This should already be the case due to AMP's builtinmeasure/mutate
cycles ensuring no read is happening while the mutation cycle is rearranging the DOM elements.Prototype Reference Code
A prototype of
amp-sort
in AMP code lives in https://github.com/aghassemi/amphtml/blob/filtersort-proto1/extensions/amp-sort/0.1/amp-sort.js and can be used as a reference for the final implementation.Code for the demo also lives here: https://github.com/aghassemi/amphtml/blob/filtersort-proto1/test/manual/amp-sort.amp.html
/cc @dvoytenko @ericlindley-g @derekcecillewis
The text was updated successfully, but these errors were encountered: