SlickGrid a besoin d'un tableau de données pour remplir la table. Vous pouvez le créer sous forme de chaîne en PHP et l'utiliser dans votre JavaScript lorsque vous créez votre SlickGrid.
Veuillez noter; c'est rapide, sale et non testé !
PHP
$data = '';
$i = 0;
$query = "
SELECT
`title`, `duration`, `percentComplete`, `start`, `finish`, `effortDriven`
FROM
`myTable`
";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$data .= '
data['.$i.'] = {
title: "'.$row['title'].'",
duration: "'.$row['duration'].'",
percentComplete: "'.$row['percentComplete'].'",
start: "'.$row['start'].'",
finish: "'.$row['finish'].'",
effortDriven: "'.$row['percentComplete'].'"
};
';
$i++;
}
JavaScript
<script type="text/javascript">
var grid;
var columns = [
{id:"title", name:"Title", field:"title"},
{id:"duration", name:"Duration", field:"duration"},
{id:"%", name:"% Complete", field:"percentComplete"},
{id:"start", name:"Start", field:"start"},
{id:"finish", name:"Finish", field:"finish"},
{id:"effort-driven", name:"Effort Driven", field:"effortDriven"}
];
var options = {
enableCellNavigation: false,
enableColumnReorder: false
};
$(function() {
var data = [];
<?php echo $data; ?> //This is where we echo the PHP variable $data which contains our JavaScript array as a string.
grid = new Slick.Grid($("#myGrid"), data, columns, options);
})
</script>