File tree Expand file tree Collapse file tree 2 files changed +99
-15
lines changed Expand file tree Collapse file tree 2 files changed +99
-15
lines changed Original file line number Diff line number Diff line change 3
3
<table class =" table table-bordered table-hover-imp table-striped dataTable" :id =" id" >
4
4
<thead >
5
5
<tr >
6
- <th v-for =" col in columns" >
7
- {{col }}
6
+ <th v-for =" c in columns" >
7
+ {{c }}
8
8
</th >
9
9
</tr >
10
10
</thead >
11
11
<tbody >
12
- <tr >
13
- <td v-for =" d in data " >
14
- {{d }}
12
+ <tr v-for = " d in data " >
13
+ <td v-for =" c in d " >
14
+ {{c }}
15
15
</td >
16
16
</tr >
17
17
</tbody >
@@ -37,23 +37,52 @@ export default {
37
37
watch: {
38
38
data : function (newValue ) {
39
39
if ($ .fn .dataTable .isDataTable (' #' + this .id )) {
40
- console .log (' true ' )
40
+ console .log (' foi iniciada ' )
41
41
let datatable = this .initDataTable ()
42
- console .log (datatable )
42
+ console .log (' antes limpar ' )
43
43
datatable .clear ()
44
44
datatable .draw ()
45
+
46
+ datatable .rows .add (newValue).draw ()
47
+ console .log (datatable .data )
45
48
}
46
49
else {
47
-
48
50
console .log (' false' )
49
51
}
50
52
}
51
53
},
52
54
methods: {
53
55
clear () {
56
+ console .log (' clear method' )
54
57
let datatable = this .initDataTable ()
55
- datatable .clear ()
56
- datatable .draw ()
58
+ console .log (' antes' )
59
+ console .log (' columns' , datatable .columns ())
60
+ console .log (' columns' , datatable .columns ().indexes ())
61
+ console .log (' rows' , datatable .rows ().data ())
62
+ // datatable.clear()
63
+ // datatable.draw()
64
+ console .log (' depois' )
65
+ datatable .rows .add ([{
66
+ ' col1' : ' ADICIONADO1' ,
67
+ ' col2' : ' ADICIONADO2'
68
+ }]).draw ()
69
+ // console.log('columns', datatable.columns())
70
+ // datatable.rows().invalidate().draw()
71
+ // datatable.rows.add([
72
+ // {
73
+ // 'col1': 'NOVO2',
74
+ // 'col2': 'NOVO2'
75
+ // },
76
+ // {
77
+ // 'col1': 'NOVO3',
78
+ // 'col2': 'NOVO4'
79
+ // },
80
+ // {
81
+ // 'col1': 'NOVO3',
82
+ // 'col2': 'NOVO4'
83
+ // },
84
+ // ]).draw()
85
+ // console.log('depois', datatable.rows().data())
57
86
},
58
87
initDataTable () {
59
88
return $ (' #' + this .id ).DataTable ({
Original file line number Diff line number Diff line change @@ -98,10 +98,59 @@ export default {
98
98
return {
99
99
msg: ' Welcome to Your Vue.js App' ,
100
100
ide: ' id_tabela' ,
101
- cols: [' col1' , ' col2' ],
101
+ cols: [
102
+ { ' name' : ' col1' },
103
+ { ' name' : ' col2' },
104
+ ],
102
105
data: [
103
- ' valor1' ,
104
- ' valor2'
106
+ {
107
+ ' col1' : ' NOVO2' ,
108
+ ' col2' : ' NOVO2'
109
+ },
110
+ {
111
+ ' col1' : ' NOVO3' ,
112
+ ' col2' : ' NOVO4'
113
+ },
114
+ {
115
+ ' col1' : ' NOVO2' ,
116
+ ' col2' : ' NOVO2'
117
+ },
118
+ {
119
+ ' col1' : ' NOVO3' ,
120
+ ' col2' : ' NOVO4'
121
+ },
122
+ {
123
+ ' col1' : ' NOVO2' ,
124
+ ' col2' : ' NOVO2'
125
+ },
126
+ {
127
+ ' col1' : ' NOVO3' ,
128
+ ' col2' : ' NOVO4'
129
+ },
130
+ {
131
+ ' col1' : ' NOVO2' ,
132
+ ' col2' : ' NOVO2'
133
+ },
134
+ {
135
+ ' col1' : ' NOVO3' ,
136
+ ' col2' : ' NOVO4'
137
+ },
138
+ {
139
+ ' col1' : ' NOVO2' ,
140
+ ' col2' : ' NOVO2'
141
+ },
142
+ {
143
+ ' col1' : ' NOVO3' ,
144
+ ' col2' : ' NOVO4'
145
+ },
146
+ {
147
+ ' col1' : ' NOVO2' ,
148
+ ' col2' : ' NOVO2'
149
+ },
150
+ {
151
+ ' col1' : ' NOVO3' ,
152
+ ' col2' : ' NOVO4'
153
+ },
105
154
],
106
155
}
107
156
},
@@ -111,8 +160,14 @@ export default {
111
160
},
112
161
gerarDados () {
113
162
this .data = [
114
- ' novo1' ,
115
- ' novo2'
163
+ {
164
+ ' col1' : ' NOVO2' ,
165
+ ' col2' : ' NOVO2'
166
+ },
167
+ {
168
+ ' col1' : ' NOVO3' ,
169
+ ' col2' : ' NOVO4'
170
+ },
116
171
]
117
172
},
118
173
}
You can’t perform that action at this time.
0 commit comments