質問するログイン新規登録

質問編集履歴

2

Javascriptで試した内容を追記

2020/07/29 00:57

投稿

suzuki999
suzuki999

スコア8

title CHANGED
File without changes
body CHANGED
@@ -10,8 +10,12 @@
10
10
 
11
11
  ## 現状
12
12
  v-data-table にヘッダ配列とアイテム配列を渡し表示しています。
13
- 表示している内容の中で空欄があった場合にその行の色を変更したいのですが、やり方が分かりません。
13
+ アイテム配列[shipment]欄に空欄があった場合にその行の色を変更したいのですが、やり方が分かりません。
14
14
 
15
+ 現状試したことは、items配列に入れているworkers配列に!value.shipmentを条件に行の色を変更する処理を入れてみました。
16
+
17
+ うまく動かず、現状もがいている状態です。
18
+
15
19
  Vue,Vuetifyに知見のある方、アドバイスのほどよろしくお願いします。
16
20
 
17
21
  ## ソースコード
@@ -32,5 +36,48 @@
32
36
  </template>
33
37
 
34
38
 
39
+ methods: {
40
+ //CSVをインポートさせる処理
41
+ fileChange: function (e) {
42
+ console.log(e);
43
+ const file = e;
44
+ const reader = new FileReader();
45
+ const workers = [];
35
46
 
47
+ const loadFunc = () => {
48
+ const lines = reader.result.split("\n");
49
+ lines.forEach((element) => {
50
+ const workerData = element.split(",");
51
+ if (workerData.length != 12) return;
52
+ const worker = {
53
+ TradeTerms: workerData[0],
54
+ ShipmentBy: workerData[1],
55
+ ShipTo: workerData[2],
56
+ PO: workerData[3],
57
+ CommodityDescription: workerData[4],
58
+ Manufacturer: workerData[5],
59
+ QTY: workerData[6],
60
+ Unit: workerData[7],
61
+ UnitPrice: workerData[8],
62
+ TotalPrice: workerData[9],
63
+ RequestETD: workerData[10],
64
+ Remarks: workerData[11],
65
+ };
66
+ workers.push(worker);
67
+ });
68
+ this.workers = workers;
69
+
70
+ //試したやり方(空白の行に対して色を指定)
71
+ this.workers.forEach(function (value, index) {
72
+ if (!value.ShipmentBy) {
73
+ console.log(index);
74
+ this.workers[index].style.color="red"
75
+ }
76
+ });
77
+ };
78
+ reader.onload = loadFunc;
79
+ reader.readAsBinaryString(file);
80
+ },
81
+
82
+
36
83
  ```

1

内容を簡潔なものに変更

2020/07/29 00:57

投稿

suzuki999
suzuki999

スコア8

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,5 @@
1
1
  ## やりたいこと
2
- Vuetifyのv-datatable コンポーネントにCSVをインポートし、空欄があった場合には色を変える
2
+ Vuetifyのv-datatable で特定の行の色を変える
3
3
 
4
4
 
5
5
  ## 環境
@@ -8,61 +8,22 @@
8
8
  Vurtify 2.2.11
9
9
 
10
10
 
11
- ## もしかしてveeValidateではできない?
11
+ ## 現状
12
- input系にはVeeValidateでバリデーションしているが、datatable には適用できない?
13
- ググっても同じような悩みの人が少ないみたいなので詳い方教えください。
12
+ v-data-table にヘッダ配列とアイテム配列を渡表示しています
13
+ この表示している内容の中で空欄があった場合にその行の色を変更したいのですが、やり方が分かりません。
14
14
 
15
- てこの要件を実装るにはJavascriptでべたがき?
15
+ Vue,Vuetifyに知見のある方、アドバイスのほどよろくお願い
16
- 便利なライブラリとかないものか。。。
17
16
 
18
-
19
17
  ## ソースコード
20
18
 
21
- ```Javascript
19
+ ```Javascript(一部)
22
20
  <template>
23
- <v-container fluid>
21
+
24
- <v-row align="center" justify="left">
25
- <h1>CSVインポート</h1>
26
- </v-row>
27
- <v-row align="Left" style="height: 70px;">
28
- <v-col>
29
- <div>
30
- <Dropdown></Dropdown>
31
- </div>
32
- </v-col>
33
-
34
- <v-col>
35
- <v-file-input
36
- @change="fileChange"
37
- label="CSVファイルを選択してください"
38
- id="file_input_expense"
39
- type="file"
40
- v-validate="required"
41
- ></v-file-input>
42
- </v-col>
43
-
44
- <v-col>
45
- <div align="right">
46
- <v-btn color="primary" @click="btnClick">登録</v-btn>
47
- </div>
48
- </v-col>
49
- </v-row>
50
22
  <v-row align="center" fluid>
51
23
  <v-col cols="12">
52
24
  <v-data-table :headers="headers" :items="workers" class="elevation-1" hide-details="auto">
53
25
  <template slot="items" slot-scope="props">
54
- <td class="text-xs-right">{{ props.item.TradeTerms }}</td>
26
+
55
- <td class="text-xs-right">{{ props.item.ShipmentBy }}</td>
56
- <td class="text-xs-right">{{ props.item.ShipTo }}</td>
57
- <td class="text-xs-right">{{ props.item.PO }}</td>
58
- <td class="text-xs-right">{{ props.item.CommodityDescription }}</td>
59
- <td class="text-xs-right">{{ props.item.Manufacturer }}</td>
60
- <td class="text-xs-right">{{ props.item.QTY }}</td>
61
- <td class="text-xs-right">{{ props.item.Unit }}</td>
62
- <td class="text-xs-right">{{ props.item.UnitPrice }}</td>
63
- <td class="text-xs-right">{{ props.item.TotalPrice }}</td>
64
- <td class="text-xs-right">{{ props.item.RequestETD }}</td>
65
- <td class="text-xs-right">{{ props.item.Remarks }}</td>
66
27
  </template>
67
28
  </v-data-table>
68
29
  </v-col>
@@ -70,137 +31,6 @@
70
31
  </v-container>
71
32
  </template>
72
33
 
73
- <script>
74
- import Dropdown from "@/components/Dropdown.vue";
75
34
 
76
- export default {
77
- components: {
78
- Dropdown
79
- },
80
- data: function() {
81
- return {
82
- headers: [
83
- {
84
- text: "TradeTerms",
85
- align: "left",
86
- sortable: false,
87
- value: "TradeTerms"
88
- },
89
- {
90
- text: "ShipmentBy",
91
- align: "left",
92
- sortable: false,
93
- value: "ShipmentBy"
94
- },
95
- {
96
- text: "ShipTo",
97
- align: "left",
98
- sortable: false,
99
- value: "ShipTo"
100
- },
101
- {
102
- text: "PO",
103
- align: "left",
104
- sortable: false,
105
- value: "PO"
106
- },
107
- {
108
- text: "CommodityDescription",
109
- align: "left",
110
- sortable: false,
111
- value: "CommodityDescription"
112
- },
113
- {
114
- text: "Manufacturer",
115
- align: "left",
116
- sortable: false,
117
- value: "Manufacturer"
118
- },
119
- {
120
- text: "QTY",
121
- align: "left",
122
- sortable: false,
123
- value: "QTY"
124
- },
125
- {
126
- text: "Unit",
127
- align: "left",
128
- sortable: false,
129
- value: "Unit"
130
- },
131
- {
132
- text: "UnitPrice",
133
- align: "left",
134
- sortable: false,
135
- value: "UnitPrice"
136
- },
137
- {
138
- text: "TotalPrice",
139
- align: "left",
140
- sortable: false,
141
- value: "TotalPrice"
142
- },
143
- {
144
- text: "RequestETD",
145
- align: "left",
146
- sortable: false,
147
- value: "RequestETD"
148
- },
149
- {
150
- text: "Remarks",
151
- align: "left",
152
- sortable: false,
153
- value: "Remarks"
154
- }
155
- ],
156
- workers: []
157
- };
158
- },
159
- methods: {
160
- required: value => !!value || "未入力の項目があります。",
161
- fileChange: function(e) {
162
- console.log(e);
163
- const file = e;
164
- const reader = new FileReader();
165
- const workers = [];
166
35
 
167
- const loadFunc = () => {
168
- const lines = reader.result.split("\n");
169
- lines.forEach(element => {
170
- const workerData = element.split(",");
171
- if (workerData.length != 12) return;
172
- const worker = {
173
- TradeTerms: workerData[0],
174
- ShipmentBy: workerData[1],
175
- ShipTo: workerData[2],
176
- PO: workerData[3],
177
- CommodityDescription: workerData[4],
178
- Manufacturer: workerData[5],
179
- QTY: workerData[6],
180
- Unit: workerData[7],
181
- UnitPrice: workerData[8],
182
- TotalPrice: workerData[9],
183
- RequestETD: workerData[10],
184
- Remarks: workerData[11]
185
- };
186
- workers.push(worker);
187
- });
188
- this.workers = workers;
189
- };
190
-
191
- reader.onload = loadFunc;
192
-
193
- reader.readAsBinaryString(file);
194
- },
195
-
196
- btnClick: function(e) {
197
- {
198
- alert(this.workers);
199
- }
200
- }
201
- }
202
- };
203
- </script>
204
-
205
-
206
36
  ```