| 1176 | } |
| 1177 | |
| 1178 | func (v *PricingView) computeColumnWidths(attrKeys []string) map[string]int { |
| 1179 | w := map[string]int{ |
| 1180 | "no": 4, |
| 1181 | "product": 7, |
| 1182 | "region": 6, |
| 1183 | "minprice": 9, |
| 1184 | "maxprice": 9, |
| 1185 | } |
| 1186 | for _, item := range v.FilteredItems { |
| 1187 | if len(item.Product) > w["product"] { |
| 1188 | w["product"] = len(item.Product) |
| 1189 | } |
| 1190 | if len(item.Region) > w["region"] { |
| 1191 | w["region"] = len(item.Region) |
| 1192 | } |
| 1193 | if len(item.MinPrice) > w["minprice"] { |
| 1194 | w["minprice"] = len(item.MinPrice) |
| 1195 | } |
| 1196 | if len(item.MaxPrice) > w["maxprice"] { |
| 1197 | w["maxprice"] = len(item.MaxPrice) |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | for _, k := range attrKeys { |
| 1202 | w[k] = len(k) |
| 1203 | for _, item := range v.FilteredItems { |
| 1204 | if val, ok := item.Attrs[k]; ok && val != nil { |
| 1205 | if len(*val) > w[k] { |
| 1206 | w[k] = len(*val) |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | if w[k] < 6 { |
| 1211 | w[k] = 6 |
| 1212 | } |
| 1213 | } |
| 1214 | return w |
| 1215 | } |
| 1216 | |
| 1217 | // buildResultRow renders one table row. |
| 1218 | // |