-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ebay-table): support column sorting (#2291)
- Loading branch information
Showing
9 changed files
with
1,269 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ebay/ebayui-core": minor | ||
--- | ||
|
||
feat(ebay-table): suppport column sorting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import data from "./data.json"; | ||
import { type TableSort } from "../component"; | ||
class { | ||
declare state: { | ||
sorted: Record<string, TableSort>; | ||
data: typeof data; | ||
}; | ||
onCreate() { | ||
this.state = { sorted: {}, data }; | ||
} | ||
onSort(event: { sorted: Record<string, TableSort> }, ...params: any) { | ||
this.state.sorted = event.sorted; | ||
this.state.data = [...data].sort((a, b) => { | ||
if (this.state.sorted.listPriceCol === "asc") { | ||
return ( | ||
Number(a.listPrice.substring(1)) - | ||
Number(b.listPrice.substring(1)) | ||
); | ||
} else if (this.state.sorted.listPriceCol === "desc") { | ||
return ( | ||
Number(b.listPrice.substring(1)) - | ||
Number(a.listPrice.substring(1)) | ||
); | ||
} else if (this.state.sorted.quantityCol === "asc") { | ||
return ( | ||
Number(a.quantityAvailable) - Number(b.quantityAvailable) | ||
); | ||
} else if (this.state.sorted.quantityCol === "desc") { | ||
return ( | ||
Number(b.quantityAvailable) - Number(a.quantityAvailable) | ||
); | ||
} | ||
return 0; | ||
}); | ||
this.emit("sort", event, ...params); | ||
} | ||
} | ||
<ebay-table on-sort("onSort") ...input> | ||
<@header name="sellerCol" column-type="row-header"> | ||
Seller | ||
</@header> | ||
<@header name="itemCol"> | ||
Item | ||
</@header> | ||
<@header name="statusCol"> | ||
Status | ||
</@header> | ||
<@header | ||
name="listPriceCol" | ||
column-type="numeric" | ||
sort=(state.sorted.listPriceCol || "none") | ||
> | ||
List Price | ||
</@header> | ||
<@header | ||
name="quantityCol" | ||
column-type="numeric" | ||
sort=(state.sorted.quantityCol || "none") | ||
> | ||
Quantity Available | ||
</@header> | ||
<@header name="orderCol"> | ||
Orders | ||
</@header> | ||
<@header name="watchersCol" column-type="numeric"> | ||
Watchers | ||
</@header> | ||
<@header name="protectionCol" column-type="numeric"> | ||
Protection | ||
</@header> | ||
<@header name="shippingCol"> | ||
Shipping | ||
</@header> | ||
<@header name="deliveryCol"> | ||
Delivery | ||
</@header> | ||
<for|r| of=state.data> | ||
<@row> | ||
<@cell>${r.seller}</@cell> | ||
<@cell>${r.item.title}</@cell> | ||
<@cell> | ||
<ebay-signal status=r.statusType as any> | ||
${r.status} | ||
</ebay-signal> | ||
</@cell> | ||
<@cell>${r.listPrice}</@cell> | ||
<@cell>${r.quantityAvailable}</@cell> | ||
<@cell> | ||
<a href="https://ebay.com"> | ||
${r.orders.number} | ||
</a> | ||
</@cell> | ||
<@cell>${r.watchers}</@cell> | ||
<@cell>${r.protection}</@cell> | ||
<@cell>${r.shipping}</@cell> | ||
<@cell>${r.delivery}</@cell> | ||
</@row> | ||
</for> | ||
</ebay-table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import data from "./data.json"; | ||
|
||
<ebay-table ...input> | ||
<@header | ||
column-type="row-header" | ||
sort=("asc" as const) | ||
href="https://www.ebay.com" | ||
> | ||
Seller | ||
</@header> | ||
<@header>Item</@header> | ||
<@header>Status</@header> | ||
<@header column-type="numeric"> | ||
List Price | ||
</@header> | ||
<@header column-type="numeric"> | ||
Quantity Available | ||
</@header> | ||
<@header>Orders</@header> | ||
<@header column-type="numeric"> | ||
Watchers | ||
</@header> | ||
<@header column-type="numeric"> | ||
Protection | ||
</@header> | ||
<@header>Shipping</@header> | ||
<@header>Delivery</@header> | ||
<for|r| of=data> | ||
<@row> | ||
<@cell>${r.seller}</@cell> | ||
<@cell>${r.item.title}</@cell> | ||
<@cell> | ||
<ebay-signal status=r.statusType as any> | ||
${r.status} | ||
</ebay-signal> | ||
</@cell> | ||
<@cell>${r.listPrice}</@cell> | ||
<@cell>${r.quantityAvailable}</@cell> | ||
<@cell> | ||
<a href="https://ebay.com"> | ||
${r.orders.number} | ||
</a> | ||
</@cell> | ||
<@cell>${r.watchers}</@cell> | ||
<@cell>${r.protection}</@cell> | ||
<@cell>${r.shipping}</@cell> | ||
<@cell>${r.delivery}</@cell> | ||
</@row> | ||
</for> | ||
</ebay-table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import data from "./data.json"; | ||
import { type TableSort } from "../component"; | ||
class { | ||
declare state: { | ||
sorted: Record<string, TableSort>; | ||
}; | ||
onCreate() { | ||
this.state = { sorted: { sellerCol: "asc" } }; | ||
} | ||
onSort(event: { sorted: Record<string, TableSort> }, ...params: any) { | ||
this.state.sorted = event.sorted; | ||
this.emit("sort", event, ...params); | ||
} | ||
} | ||
|
||
<ebay-table on-sort("onSort") ...input> | ||
<@header | ||
name="sellerCol" | ||
column-type="row-header" | ||
sort=(state.sorted.sellerCol || "none") | ||
> | ||
Seller | ||
</@header> | ||
<@header name="itemCol" sort=(state.sorted.itemCol || "none")> | ||
Item | ||
</@header> | ||
<@header name="statusCol" sort=(state.sorted.statusCol || "none")> | ||
Status | ||
</@header> | ||
<@header | ||
name="listPriceCol" | ||
column-type="numeric" | ||
sort=(state.sorted.listPriceCol || "none") | ||
> | ||
List Price | ||
</@header> | ||
<@header | ||
name="quantityCol" | ||
column-type="numeric" | ||
sort=(state.sorted.quantityCol || "none") | ||
> | ||
Quantity Available | ||
</@header> | ||
<@header name="orderCol" sort=(state.sorted.orderCol || "none")> | ||
Orders | ||
</@header> | ||
<@header | ||
name="watchersCol" | ||
column-type="numeric" | ||
sort=(state.sorted.watchersCol || "none") | ||
> | ||
Watchers | ||
</@header> | ||
<@header | ||
name="protectionCol" | ||
column-type="numeric" | ||
sort=(state.sorted.protectionCol || "none") | ||
> | ||
Protection | ||
</@header> | ||
<@header name="shippingCol" sort=(state.sorted.shippingCol || "none")> | ||
Shipping | ||
</@header> | ||
<@header name="deliveryCol" sort=(state.sorted.deliveryCol || "none")> | ||
Delivery | ||
</@header> | ||
<for|r| of=data> | ||
<@row> | ||
<@cell>${r.seller}</@cell> | ||
<@cell>${r.item.title}</@cell> | ||
<@cell> | ||
<ebay-signal status=r.statusType as any> | ||
${r.status} | ||
</ebay-signal> | ||
</@cell> | ||
<@cell>${r.listPrice}</@cell> | ||
<@cell>${r.quantityAvailable}</@cell> | ||
<@cell> | ||
<a href="https://ebay.com"> | ||
${r.orders.number} | ||
</a> | ||
</@cell> | ||
<@cell>${r.watchers}</@cell> | ||
<@cell>${r.protection}</@cell> | ||
<@cell>${r.shipping}</@cell> | ||
<@cell>${r.delivery}</@cell> | ||
</@row> | ||
</for> | ||
</ebay-table> |
Oops, something went wrong.