Skip to content

Commit 09fe397

Browse files
committed
Trying to update table rows
1 parent 0eefcbb commit 09fe397

File tree

2 files changed

+99
-15
lines changed

2 files changed

+99
-15
lines changed

src/components/DataTable.vue

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
<table class="table table-bordered table-hover-imp table-striped dataTable" :id="id">
44
<thead>
55
<tr>
6-
<th v-for="col in columns">
7-
{{col}}
6+
<th v-for="c in columns">
7+
{{c}}
88
</th>
99
</tr>
1010
</thead>
1111
<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}}
1515
</td>
1616
</tr>
1717
</tbody>
@@ -37,23 +37,52 @@ export default {
3737
watch: {
3838
data: function(newValue) {
3939
if($.fn.dataTable.isDataTable('#' + this.id)) {
40-
console.log('true')
40+
console.log('foi iniciada')
4141
let datatable = this.initDataTable()
42-
console.log(datatable)
42+
console.log('antes limpar')
4343
datatable.clear()
4444
datatable.draw()
45+
46+
datatable.rows.add(newValue).draw()
47+
console.log(datatable.data)
4548
}
4649
else {
47-
4850
console.log('false')
4951
}
5052
}
5153
},
5254
methods: {
5355
clear() {
56+
console.log('clear method')
5457
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())
5786
},
5887
initDataTable() {
5988
return $('#' + this.id).DataTable({

src/components/HelloWorld.vue

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,59 @@ export default {
9898
return {
9999
msg: 'Welcome to Your Vue.js App',
100100
ide: 'id_tabela',
101-
cols: ['col1', 'col2'],
101+
cols: [
102+
{ 'name': 'col1' },
103+
{ 'name': 'col2' },
104+
],
102105
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+
},
105154
],
106155
}
107156
},
@@ -111,8 +160,14 @@ export default {
111160
},
112161
gerarDados() {
113162
this.data = [
114-
'novo1',
115-
'novo2'
163+
{
164+
'col1': 'NOVO2',
165+
'col2': 'NOVO2'
166+
},
167+
{
168+
'col1': 'NOVO3',
169+
'col2': 'NOVO4'
170+
},
116171
]
117172
},
118173
}

0 commit comments

Comments
 (0)