corrade-nucleus-nucleons – Blame information for rev 20
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | /** |
2 | * @author: Dennis Hernández |
||
3 | * @webSite: http://djhvscf.github.io/Blog |
||
4 | * @version: v1.0.1 |
||
5 | */ |
||
6 | |||
7 | (function ($) { |
||
8 | |||
9 | 'use strict'; |
||
10 | |||
11 | var isSearch = false; |
||
12 | |||
13 | var rowAttr = function (row, index) { |
||
14 | return { |
||
15 | id: 'customId_' + index |
||
16 | }; |
||
17 | }; |
||
18 | |||
19 | $.extend($.fn.bootstrapTable.defaults, { |
||
20 | reorderableRows: false, |
||
21 | onDragStyle: null, |
||
22 | onDropStyle: null, |
||
23 | onDragClass: "reorder_rows_onDragClass", |
||
24 | dragHandle: null, |
||
25 | useRowAttrFunc: false, |
||
26 | onReorderRowsDrag: function (table, row) { |
||
27 | return false; |
||
28 | }, |
||
29 | onReorderRowsDrop: function (table, row) { |
||
30 | return false; |
||
31 | }, |
||
32 | onReorderRow: function (newData) { |
||
33 | return false; |
||
34 | } |
||
35 | }); |
||
36 | |||
37 | $.extend($.fn.bootstrapTable.Constructor.EVENTS, { |
||
38 | 'reorder-row.bs.table': 'onReorderRow' |
||
39 | }); |
||
40 | |||
41 | var BootstrapTable = $.fn.bootstrapTable.Constructor, |
||
42 | _init = BootstrapTable.prototype.init, |
||
43 | _initSearch = BootstrapTable.prototype.initSearch; |
||
44 | |||
45 | BootstrapTable.prototype.init = function () { |
||
46 | |||
47 | if (!this.options.reorderableRows) { |
||
48 | _init.apply(this, Array.prototype.slice.apply(arguments)); |
||
49 | return; |
||
50 | } |
||
51 | |||
52 | var that = this; |
||
53 | if (this.options.useRowAttrFunc) { |
||
54 | this.options.rowAttributes = rowAttr; |
||
55 | } |
||
56 | |||
57 | var onPostBody = this.options.onPostBody; |
||
58 | this.options.onPostBody = function () { |
||
59 | setTimeout(function () { |
||
60 | that.makeRowsReorderable(); |
||
61 | onPostBody.apply(); |
||
62 | }, 1); |
||
63 | }; |
||
64 | |||
65 | _init.apply(this, Array.prototype.slice.apply(arguments)); |
||
66 | }; |
||
67 | |||
68 | BootstrapTable.prototype.initSearch = function () { |
||
69 | _initSearch.apply(this, Array.prototype.slice.apply(arguments)); |
||
70 | |||
71 | if (!this.options.reorderableRows) { |
||
72 | return; |
||
73 | } |
||
74 | |||
75 | //Known issue after search if you reorder the rows the data is not display properly |
||
76 | //isSearch = true; |
||
77 | }; |
||
78 | |||
79 | BootstrapTable.prototype.makeRowsReorderable = function () { |
||
80 | if (this.options.cardView) { |
||
81 | return; |
||
82 | } |
||
83 | |||
84 | var that = this; |
||
85 | this.$el.tableDnD({ |
||
86 | onDragStyle: that.options.onDragStyle, |
||
87 | onDropStyle: that.options.onDropStyle, |
||
88 | onDragClass: that.options.onDragClass, |
||
89 | onDrop: that.onDrop, |
||
90 | onDragStart: that.options.onReorderRowsDrag, |
||
91 | dragHandle: that.options.dragHandle |
||
92 | }); |
||
93 | }; |
||
94 | |||
95 | BootstrapTable.prototype.onDrop = function (table, droppedRow) { |
||
96 | var tableBs = $(table), |
||
97 | tableBsData = tableBs.data('bootstrap.table'), |
||
98 | tableBsOptions = tableBs.data('bootstrap.table').options, |
||
99 | row = null, |
||
100 | newData = []; |
||
101 | |||
102 | for (var i = 0; i < table.tBodies[0].rows.length; i++) { |
||
103 | row = $(table.tBodies[0].rows[i]); |
||
104 | newData.push(tableBsOptions.data[row.data('index')]); |
||
105 | row.data('index', i).attr('data-index', i); |
||
106 | } |
||
107 | |||
108 | tableBsOptions.data = tableBsOptions.data.slice(0, tableBsData.pageFrom - 1) |
||
109 | .concat(newData) |
||
110 | .concat(tableBsOptions.data.slice(tableBsData.pageTo)); |
||
111 | |||
112 | //Call the user defined function |
||
113 | tableBsOptions.onReorderRowsDrop.apply(table, [table, droppedRow]); |
||
114 | |||
115 | //Call the event reorder-row |
||
116 | tableBsData.trigger('reorder-row', newData); |
||
117 | }; |
||
118 | })(jQuery); |