Guest User

Untitled

a guest
Feb 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>DataGrid: Advanced Filter Tests</title>
  8.  
  9. <script src="../webcomponentsjs/webcomponents-lite.js"></script>
  10. <link rel="import" href="../polymer/polymer.html" />
  11. <link rel="import" href="../px-theme/px-theme-styles.html">
  12. <link rel="import" href="px-data-grid.html" />
  13. <link rel="import" href="px-data-grid-paginated.html" />
  14.  
  15. <style is="custom-style">
  16. html, body {
  17. margin: 10px;
  18. font-size: 15px;
  19. }
  20. </style>
  21.  
  22. <custom-style>
  23. <style include="px-theme-styles" is="custom-style"></style>
  24. </custom-style>
  25.  
  26. </head>
  27.  
  28. <body>
  29. <dom-bind >
  30. <template is="dom-bind" id="table" >
  31.  
  32.  
  33. <div style="height:850px; width:850px">
  34. <h2>Filterable Paginated </h2>
  35. <px-data-grid-paginated
  36. table-data='[
  37. {
  38. "Tag Name coz we like really long names": "Tag_Temperature_With_Data_15",
  39. "Correlated Tags": "15",
  40. "Temp" :"37.5",
  41. "Units": "celsius",
  42. "Description": "This is a test for filtering data in celsius",
  43. "Maintenance Date": "04-12-1985",
  44. "Asset": "Tag_Temperature_With_Data_15 GE_SAN_RAMON_1111111",
  45. "Domain": "GE_SanRamon1100",
  46. "Location" : "North America",
  47. "Timezone" :"PST"
  48. },
  49. {
  50. "Tag Name coz we like really long names": "Tag_Temperature_With_Data_15",
  51. "Correlated Tags": "15",
  52. "Temp" :"10.23",
  53. "Units": "Some fancy temperature units",
  54. "Description": "This is a test for filtering data",
  55. "Maintenance Date": "04-12-1985",
  56. "Asset": "Tag_Temperature_With_Data_15 GE_SAN_RAMON_1111111",
  57. "Domain": "GE_SanRamon1100",
  58. "Location" : "North America",
  59. "Timezone" :"PST"
  60. },
  61. {
  62. "Tag Name coz we like really long names": "Tag_Temperature_With_Data_14",
  63. "Correlated Tags": "14",
  64. "Units": "Fahrenheit",
  65. "Temp" :"7654.111",
  66. "Description": "This is a test for filtering data in fahrenheit not in celsius",
  67. "Maintenance Date": "04-12-1985",
  68. "Asset": "Tag_Temperature_With_Data_14 GE_SAN_RAMON_1111111",
  69. "Domain": "GE_Brazil_1100",
  70. "Location" : "South America",
  71. "Timezone" :"PST"
  72. },
  73. {
  74. "Tag Name coz we like really long names": "Tag_Temperature_With_Data_19",
  75. "Correlated Tags": "19",
  76. "Units": "celsius",
  77. "Temp" :"6",
  78. "Description": "This is AViD Tag Temperature Type description in celsius",
  79. "Maintenance Date": "10-12-1994",
  80. "Asset": "Tag_Temperature_With_Data_19 GE_SAN_RAMON_1111111",
  81. "Domain": "GE_Chile_1111",
  82. "Location" : "South America",
  83. "Timezone" :"PST"
  84. },
  85. {
  86. "Tag Name coz we like really long names": "Tag_pressure_With_Data_48",
  87. "Correlated Tags": "48",
  88. "Units": "at",
  89. "Temp" :"1210.2234",
  90. "Description": "This is AViD Tag pressure2 Type description in celsius",
  91. "Maintenance Date": "1995-11-13",
  92. "Asset": "Tag_pressure_With_Data_48 GE_SAN_RAMON_1111111",
  93. "Domain": "GE_Brazil_1111",
  94. "Location" : "South America",
  95. "Timezone" :"PST"
  96. },
  97. {
  98. "Tag Name coz we like really long names": "Tag_Temperature_With_Data_05",
  99. "Correlated Tags": "05",
  100. "Units": "Celsius",
  101. "Temp" :"98.33233",
  102. "Description": ".../unit15/This is AViD Tag Temperature Type description",
  103. "Maintenance Date": "1996-12-12",
  104. "Asset": "Tag_Temperature_With_Data_05 GEffSAN_RAMON_1111111",
  105. "Domain": "GE_Dubai_1145",
  106. "Location" : "Asia",
  107. "Timezone" :"PST"
  108. }
  109. ]'
  110. columns='[
  111. {
  112. "name":"Tag Name coz we like really long names",
  113. "path":"Tag Name coz we like really long names",
  114. "hidden":false,
  115. "editable":false,
  116. "frozen":false,
  117. "id":"Tag Name coz we like really long names[string]"
  118. },
  119. {
  120. "name":"Correlated_Tag_Data",
  121. "type": "number",
  122. "path":"Correlated Tags",
  123. "hidden":false,
  124. "editable":true,
  125. "frozen":false,
  126. "id":"Correlated Tags[number]",
  127. "renderer":"px-data-grid-number-renderer",
  128. "minBound" : 10,
  129. "maxBound" : 150
  130. },
  131. {
  132. "name":"Temp",
  133. "type": "number",
  134. "path":"Temp",
  135. "hidden":false,
  136. "editable":true,
  137. "frozen":false,
  138. "id":"Temp[number]",
  139. "renderer":"px-data-grid-number-renderer"
  140. },
  141. {
  142. "name":"Maintenance Date",
  143. "type": "date",
  144. "path":"Maintenance Date",
  145. "hidden":false,
  146. "editable":true,
  147. "frozen":false,
  148. "id":"Maintenance Date[date]",
  149. "renderer":"px-data-grid-date-renderer"
  150. },
  151. {
  152. "name":"Units",
  153. "path":"Units",
  154. "type":"string",
  155. "editable":true,
  156. "required":true,
  157. "frozen":false,
  158. "id":"Units[string]",
  159. "renderer":"px-data-grid-string-renderer"
  160. },
  161. {
  162. "name":"Description",
  163. "path":"Description",
  164. "type":"string",
  165. "editable":true,
  166. "required":true,
  167. "frozen":false,
  168. "id":"Description[string]",
  169. "renderer":"px-data-grid-string-renderer"
  170. },
  171. {
  172. "name":"Asset",
  173. "path":"Asset",
  174. "type":"string",
  175. "editable":true,
  176. "required":true,
  177. "frozen":false,
  178. "renderer":"px-data-grid-string-renderer",
  179. "id":"Asset[string]"
  180. },
  181. {
  182. "name":"Domain",
  183. "path":"Domain",
  184. "type":"string",
  185. "editable":true,
  186. "required":true,
  187. "frozen":false,
  188. "renderer":"px-data-grid-string-renderer",
  189. "id":"Domain[string]"
  190.  
  191. },
  192. {
  193. "name":"Location",
  194. "path":"Location",
  195. "type":"string",
  196. "editable":false,
  197. "required":true,
  198. "frozen":false,
  199. "id":"Location[string]"
  200. },
  201. {
  202. "name":"Timezone",
  203. "path":"Timezone",
  204. "type":"string",
  205. "editable":true,
  206. "required":true,
  207. "frozen":false,
  208. "renderer":"px-data-grid-string-renderer",
  209. "id":"Timezone[string]"
  210. }
  211. ]'
  212. selection-mode="multi"
  213. default-column-width="180px"
  214. flex-to-size
  215. default-column-flex="0"
  216. filterable
  217. editable
  218. language="en"
  219. action-menu
  220. auto-height
  221. auto-filter
  222.  
  223. column-reordering-allowed
  224. table-actions='[{"name":"Export CSV","id":"CSV"}]'
  225. item-actions='[{"name":"Add Row","id":"add"},{"name":"Delete Row","id":"delete"}]'
  226. on-table-action="tableActionListener"
  227. page-size="5"
  228.  
  229. >
  230. </px-data-grid-paginated>
  231. </div>
  232. </template>
  233. </dom-bind>
  234. <script>
  235.  
  236. addEventListener('WebComponentsReady', function() {
  237. var template = document.getElementById('table');
  238. template.tableActionListener= function(evt) {
  239. window.alert('Table Action ' + evt.detail.id);
  240. console.log ("Table Action happening");
  241. if (evt.detail.id === 'CSV') {
  242. this.exportToCsv();
  243. }
  244. },
  245.  
  246. template.exportToCsv= function() {
  247. const grid = this.shadowRoot.getElementById('table');
  248. const data = grid.getData();
  249. const columns = grid._getVisibleColumns();
  250. let csvContent = 'data:text/csv;charset=utf-8,';
  251.  
  252. csvContent += columns.map((column) => grid._resolveColumnHeader(column)).join(',') + '\r\n';
  253. data.forEach((item) => {
  254. csvContent += Object.keys(item).map((key) => item[key]).join(',') + '\r\n';
  255. });
  256.  
  257. const encodedUri = encodeURI(csvContent);
  258. const link = document.createElement('a');
  259. link.setAttribute('href', encodedUri);
  260. link.setAttribute('download', 'table_data.csv');
  261. document.body.appendChild(link);
  262.  
  263. link.click();
  264.  
  265. }
  266. });
  267. </script>
  268.  
  269. </body>
  270. </html>
Add Comment
Please, Sign In to add comment