mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
Sort Extension dates formatted MMM d yyyy, HH:mm
Since data tables supports sorting by value and it is possible to parse using the same formatter that the extensions use, it is possible to support sorting by dates. Affects issues: - Fixed #1305
This commit is contained in:
parent
18a1708a09
commit
3961e251ca
@ -18,12 +18,16 @@ package com.djrapitops.plan.delivery.rendering.html.structure;
|
||||
|
||||
import com.djrapitops.plan.extension.table.Table;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class DynamicHtmlTable implements HtmlTable {
|
||||
private final Header[] headers;
|
||||
private final List<Object[]> rows;
|
||||
|
||||
private final SimpleDateFormat dateFormat = new SimpleDateFormat("MMM d yyyy, HH:mm");
|
||||
|
||||
public DynamicHtmlTable(Header[] headers, List<Object[]> rows) {
|
||||
this.headers = headers;
|
||||
this.rows = rows;
|
||||
@ -76,9 +80,7 @@ public class DynamicHtmlTable implements HtmlTable {
|
||||
if (i > headerLength) {
|
||||
builtBody.append("<td>-");
|
||||
} else {
|
||||
builtBody.append("<td>");
|
||||
Object value = row[i];
|
||||
builtBody.append(value != null ? value : '-');
|
||||
appendValue(builtBody, row[i]);
|
||||
}
|
||||
builtBody.append("</td>");
|
||||
} catch (ClassCastException | ArrayIndexOutOfBoundsException e) {
|
||||
@ -87,4 +89,14 @@ public class DynamicHtmlTable implements HtmlTable {
|
||||
}
|
||||
builtBody.append("</tr>");
|
||||
}
|
||||
|
||||
private void appendValue(StringBuilder builtBody, Object value) {
|
||||
String valueString = value != null ? value.toString() : "-";
|
||||
try {
|
||||
long time = dateFormat.parse(valueString).getTime();
|
||||
builtBody.append("<td data-order=\"").append(time).append("\">").append(valueString);
|
||||
} catch (ParseException e) {
|
||||
builtBody.append("<td>").append(valueString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user