|
8 | 8 |
|
9 | 9 | <title>Test Remote Dataset - Metro UI :: Popular HTML, CSS and JS library</title> |
10 | 10 | <style> |
11 | | - body { |
12 | | - padding-top: 60px; |
13 | | - } |
14 | | - |
15 | 11 | .product-image { |
16 | 12 | height: 200px; |
17 | 13 | display: flex; |
|
75 | 71 | </div> |
76 | 72 | </nav> |
77 | 73 |
|
78 | | -<div class="container-fluid"> |
| 74 | +<div class="container-fluid pt-10"> |
79 | 75 | <div class="container"> |
80 | | - |
81 | 76 | <div data-role="remote-dataset" |
82 | | - data-caption="Products" |
83 | | - data-offset-key="skip" |
84 | | - data-data-key="products" |
| 77 | + data-caption="Products:" |
| 78 | + data-key-offset="skip" |
| 79 | + data-key-data="products" |
| 80 | + data-key-limit="limit" |
| 81 | + data-key-total="total" |
| 82 | + data-key-sort="sortBy" |
| 83 | + data-key-order="order" |
| 84 | + data-key-search="q" |
85 | 85 | data-url='https://dummyjson.com/products' |
86 | | - data-search-url='https://dummyjson.com/products/search' |
87 | | - data-search-key="q" |
88 | | - data-template="datasetTemplate" |
89 | | - data-cls-body="row" |
90 | | - data-cls-item="cell-ld-6 cell-md-4" |
| 86 | + data-url-search='https://dummyjson.com/products/search' |
| 87 | + data-cls-body="row gap-4 mt-4" |
91 | 88 | data-cls-pagination="mt-4 d-flex flex-justify-center" |
92 | 89 | data-sort="rating:desc" |
93 | | - data-sort-rules="price:asc:Price:<span class='mif-arrow-up'>,price:desc:Price:<span class='mif-arrow-down'>,rating:desc:By rating:<span class='mif-star-empty'>" |
94 | | - ></div> |
95 | | - |
| 90 | + data-sort-rules="price:asc:Price Asc:<span class='mif-arrow-up'>,price:desc:Price Desc:<span class='mif-arrow-down'>,rating:desc:By rating:<span class='mif-star-empty'>" |
| 91 | + data-on-draw-entry="drawEntry" |
| 92 | + data-limit="6" |
| 93 | + data-rows-steps="6, 24, 48, 96, 192" |
| 94 | + ></div> |
96 | 95 | </div> |
97 | 96 | </div> |
98 | 97 |
|
99 | 98 | <script src="../lib/metro.js"></script> |
100 | 99 | <script> |
101 | | - function datasetTemplate(data) { |
102 | | - return data ? ` |
103 | | - <div class="card p-4 h-100"> |
104 | | - <div class="product-image"><img src="${data.thumbnail}" alt="${data.title}"/></div> |
105 | | - <div class="product-title">${data.title}</div> |
106 | | - <div> |
107 | | - <span class="product-brand bg-sand">${data.brand ? data.brand : 'Noname'}</span> |
108 | | - ${data.tags.map(sel => `<span class="mr-1 product-brand bg-light-sand">${sel}</span>`).join('')} |
109 | | - </div> |
110 | | - <div><span class="product-desc">${data.description}</span></div> |
111 | | - <div class="row mt-auto"> |
112 | | - <div class="cell-4"> |
113 | | - <div class="product-price"><span class="">$${data.price}</span></div> |
| 100 | + function drawEntry(entry, index, body) { |
| 101 | + const productCard = entry ? ` |
| 102 | + <div class="cell-ld-6 cell-md-4"> |
| 103 | + <div class="card p-4 h-100"> |
| 104 | + <div class="product-image"><img src="${entry.thumbnail}" alt="${entry.title}"/></div> |
| 105 | + <div class="product-title">${entry.title}</div> |
| 106 | + <div> |
| 107 | + <span class="product-brand bg-sand">${entry.brand ? entry.brand : 'Noname'}</span> |
| 108 | + ${entry.tags.map(sel => `<span class="mr-1 product-brand bg-light-sand">${sel}</span>`).join('')} |
114 | 109 | </div> |
115 | | - <div class="cell-8"> |
116 | | - <div class="product-rating text-right"> |
117 | | - <input data-role="rating" data-static="true" data-value="${data.rating}" data-stared-color="#f2c313" data-message="(${data.rating})"/> |
| 110 | + <div><span class="product-desc">${entry.description}</span></div> |
| 111 | + <div class="row mt-auto"> |
| 112 | + <div class="cell-4"> |
| 113 | + <div class="product-price"><span class="">$${entry.price}</span></div> |
| 114 | + </div> |
| 115 | + <div class="cell-8"> |
| 116 | + <div class="product-rating text-right"> |
| 117 | + <input data-role="rating" data-static="true" data-value="${entry.rating}" data-stared-color="#f2c313" data-message="(${entry.rating})"/> |
| 118 | + </div> |
118 | 119 | </div> |
119 | 120 | </div> |
120 | | - </div> |
121 | | - <div class="d-flex flex-row gap-2 mt-4"> |
122 | | - <button class="button success"><span data-role="eval">{{ Metro.locale.label_buy}}</span> <span class="mif-add-shopping-cart icon"></span></button> |
123 | | - |
124 | | - <button class="ml-auto button square outline fg-orange"><span class="mif-star-empty"></span></button> |
125 | | - <button class="button info"><span data-role="eval">{{ Metro.locale.label_details}}</span></button> |
126 | | - </div> |
| 121 | + <div class="d-flex flex-row gap-2 mt-4"> |
| 122 | + <button class="button success"><span data-role="eval">{{ Metro.locale.label_buy}}</span> <span class="mif-add-shopping-cart icon"></span></button> |
| 123 | + |
| 124 | + <button class="ml-auto button square outline fg-orange"><span class="mif-star-empty"></span></button> |
| 125 | + <button class="button info"><span data-role="eval">{{ Metro.locale.label_details}}</span></button> |
| 126 | + </div> |
| 127 | + </div> |
127 | 128 | </div> |
128 | 129 | ` : ``; |
| 130 | + |
| 131 | + $(body).append(productCard); |
| 132 | + } |
| 133 | + |
| 134 | + function drawPriceHint(value) { |
| 135 | + return "$"+(+value).format(0, 3, " "); |
| 136 | + } |
| 137 | + |
| 138 | + function addPriceFilter(min, max) { |
| 139 | + const ds = Metro.getPlugin(".remote-dataset", "remote-dataset"); |
| 140 | + ds.addParam("min-price", min); |
| 141 | + ds.addParam("max-price", max); |
| 142 | + ds.load(); |
129 | 143 | } |
130 | 144 | </script> |
131 | 145 | </body> |
|
0 commit comments