I have a DataGrid where there are columns that represent date. Now I want to group them by month. These dates are not static, rather changes everyday i.e. start date is always the current date. As a result, the example we have in the user guide for fix columns needs some tweaking to meet this needs.
This is how I am collecting the columns:
SimpleDateFormat sdfMMM = new SimpleDateFormat("MMMM");
private void initDataGridColumnHeaders(String bucket){
Date planDate = timeSource.currentTimestamp();
ArrayList<String> janList = new ArrayList<>();
ArrayList<String> febList = new ArrayList<>();
ArrayList<String> marList = new ArrayList<>();
if(bucket.equalsIgnoreCase("daily")) {
for (int pd = 1; pd < 24; pd++) {
String date = sdf.format(planDate);
String columnName = "pd"+pd;
productionPlanDataGrid.getColumnNN(columnName).setCaption(date);
String month = sdfMMM.format(planDate);
if(month.equalsIgnoreCase("January")) {
janList.add(columnName);
}else if(month.equalsIgnoreCase("February")) {
febList.add(columnName);
}else if(month.equalsIgnoreCase("March")) {
marList.add(columnName);
}
planDate = DateUtils.addDays(planDate, 1);
}
}
initHeader();
// initHeader(monthList);
}
If I use the fixed Grouping as follows it works though that’s not what I am looking for-
private void initHeader() {
DataGrid.HeaderRow headerRow = productionPlanDataGrid.prependHeaderRow();
DataGrid.HeaderCell headerCell = headerRow.join("pd1", "pd2", "pd3", "pd4", "pd5");
headerCell.setText("JANUARY");
headerCell.setStyleName("center-bold");
}
Tried the following and didn’t work and not sure if this is the right approach
private void initHeader(ArrayList<String> monthList) {
DataGrid.HeaderRow headerRow = productionPlanDataGrid.prependHeaderRow();
DataGrid.HeaderCell headerCell = headerRow.join(
monthList.forEach(name -> {
System.out.println(name.toString());
})
);
headerCell.setText("OCTOBER");
headerCell.setStyleName("center-bold");
}
Thanks for any help.