SlickGrid - Display data from a SQL database

by
Jeremy Canfield |
Updated: April 09 2020
| SlickGrid articles
If using Visual Studio (ASP.NET):
Create a SQL connection:
- From Toolbox, drag SQL Datastore into Design View
- In Design View, select Configure Data Source
- In the Choose Data Source dialog box, select a connection string and select Next
- Follow the prompts to select some data from a SQL database table
If using PHP, let's grab some data from a SQL database and display the data in the table.
<?php
$data = '';
$i = 0;
$con = new mysqli('sql_domain', 'sql_username', 'sql_password', 'database');
$sql = "select * from tablename";
$sql_query = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($sql_query)) {
$data .= '
data['.$i.'] = {
title: "'.$row['title'].'",
newcolumn: "'.$row['newcolumn'].'"
};
';
$i++;
}
?>
<script>
var grid;
var columns = [
{id: "title", name: "Title", field: "title"},
{id: "newcolumn", name: "New Column", field: "newcolumn"}
];
var options = {
enableCellNavigation: true,
enableColumnReorder: false
};
$(function () {
var data = [];
<?php echo $data; ?>
grid = new Slick.Grid("#myGrid", data, columns, options);
})
</script>
Did you find this article helpful?
If so, consider buying me a coffee over at