I am making internal dashboard with a table for top selling products. I'm using google charts table for it and I want to add a filter to display products only from this to that date. I'm trying to implement DateRange Filter control from the Google Charts Docu but I'm stuck for some time now. I get an error "Column 6 is not a date", which is understandable because it's a string. I used STR_TO_DATE in my sql query:
STR_TO_DATE(created_at, '%Y-%m-%d') AS dato
In the sql result the field seems to be of type date but when I make it into array, it's of type string again.
foreach ($dataTable as $d) {
$infoTable[] = array((int)$d['productid'], $d['product_name'], $d['brand'], $d['supplier'], (int)$d['store'], (int)$d['in stock'], $d['dato'], $d['tid'], (int)$d['quantity']);
}
How can I implement such filter? It doesn't have to be even DateRange from google chars, any suggestions how to add date filter to the table is welcome. EDIT: my javascript code for table:
function drawDashboard(tableData) {
var data = new google.visualization.arrayToDataTable(tableData);
var dashboard = new google.visualization.Dashboard(
document.getElementById('dashboard_div'));
var stringFilter = new google.visualization.ControlWrapper({
controlType: 'StringFilter',
containerId: 'string_filter_div',
options: {
filterColumnIndex: 6
}
});
// var dateRange = new google.visualization.ControlWrapper({
// controlType: 'DateRangeFilter',
// containerId: 'daterange_div',
// options: {
// filterColumnIndex: 6
// }
// });
var table = new google.visualization.ChartWrapper({
chartType: 'Table',
containerId: 'table_div1',
options: {
showRowNumber: true,
width: '90%',
page: 'enable',
pageSize: 15
}
});
dashboard.bind(stringFilter, table);
dashboard.draw(data);
}
var tableData = <?php echo json_encode($infoTable) ?>;
google.charts.setOnLoadCallback(function() {
drawDashboard(tableData);
});
<div id="dashboard_div">
<div id="string_filter_div"></div>
<div id="table_div1"></div>
<div id="daterange_div"></div>
</div>