simple-table.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import Ember from 'ember';
  19. export default Ember.Component.extend({
  20. didInsertElement: function() {
  21. var paging = this.get("paging") ? true : this.get("paging");
  22. var ordering = this.get("ordering") ? true : this.get("ordering");
  23. var info = this.get("info") ? true : this.get("info");
  24. var bFilter = this.get("bFilter") ? true : this.get("bFilter");
  25. // Defines sorter for the columns if not default.
  26. // Can also specify a custom sorter.
  27. var i;
  28. var colDefs = [];
  29. if (this.get("colTypes")) {
  30. var typesArr = this.get("colTypes").split(' ');
  31. var targetsArr = this.get("colTargets").split(' ');
  32. for (i = 0; i < typesArr.length; i++) {
  33. console.log(typesArr[i] + " " + targetsArr[i]);
  34. colDefs.push({
  35. type: typesArr[i],
  36. targets: parseInt(targetsArr[i])
  37. });
  38. }
  39. }
  40. // Defines initial column and sort order.
  41. var orderArr = [];
  42. if (this.get("colsOrder")) {
  43. var cols = this.get("colsOrder").split(' ');
  44. for (i = 0; i < cols.length; i++) {
  45. var col = cols[i].split(',');
  46. if (col.length != 2) {
  47. continue;
  48. }
  49. var order = col[1].trim();
  50. if (order != 'asc' && order != 'desc') {
  51. continue;
  52. }
  53. var colOrder = [];
  54. colOrder.push(parseInt(col[0]));
  55. colOrder.push(order);
  56. orderArr.push(colOrder);
  57. }
  58. }
  59. if (orderArr.length == 0) {
  60. var defaultOrder = [0, 'asc'];
  61. orderArr.push(defaultOrder);
  62. }
  63. console.log(orderArr[0]);
  64. Ember.$('#' + this.get('table-id')).DataTable({
  65. "paging": paging,
  66. "ordering": ordering,
  67. "info": info,
  68. "bFilter": bFilter,
  69. "order": orderArr,
  70. "columnDefs": colDefs
  71. });
  72. }
  73. });