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 =" c in columns" >
7
- {{c}}
6
+ <th v-for =" c in columns" >
7
+ <span v-for =" prop in c" >
8
+ {{prop}}
9
+ </span >
8
10
</th >
9
11
</tr >
10
12
</thead >
21
23
<br >
22
24
{{columns}}
23
25
<br >
24
- {{data}}
26
+ {{initDataTable(). data()[0] }}
25
27
</div >
26
28
</div >
27
29
</template >
@@ -36,58 +38,35 @@ export default {
36
38
},
37
39
watch: {
38
40
data : function (newValue ) {
39
- if ($ .fn .dataTable .isDataTable (' #' + this .id )) {
40
- console .log (' foi iniciada' )
41
- let datatable = this .initDataTable ()
42
- console .log (' antes limpar' )
43
- datatable .clear ()
44
- datatable .draw ()
45
-
46
- datatable .rows .add (newValue).draw ()
47
- console .log (datatable .data )
48
- }
49
- else {
50
- console .log (' false' )
51
- }
41
+ let datatable = this .initDataTable ()
42
+ datatable .clear ()
43
+ datatable .rows .add (newValue).draw ()
44
+ console .log (datatable .data )
52
45
}
53
46
},
54
47
methods: {
48
+ addRow (newRow ) {
49
+ let datatable = this .initDataTable ()
50
+ datatable .rows .add ([newRow]).draw ()
51
+ },
55
52
clear () {
56
- console .log (' clear method' )
57
53
let datatable = this .initDataTable ()
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())
54
+ datatable .clear ().draw ()
86
55
},
87
56
initDataTable () {
88
- return $ (' #' + this .id ).DataTable ({
89
- ' retrieve' : true
90
- })
57
+ if (! $ .fn .dataTable .isDataTable (' #' + this .id )) {
58
+ return $ (' #' + this .id ).DataTable ({
59
+ retrieve: true ,
60
+ columns: this .columns ,
61
+ language: {
62
+ url: ' //cdn.datatables.net/plug-ins/1.10.13/i18n/Portuguese-Brasil.json'
63
+ },
64
+ autoWidth: true
65
+ })
66
+ }
67
+ else {
68
+ return $ (' #' + this .id ).DataTable ()
69
+ }
91
70
}
92
71
},
93
72
mounted () {
0 commit comments