Skip to content

Commit 693d237

Browse files
author
Nuno
committed
examples added
1 parent 0caa35d commit 693d237

File tree

4 files changed

+165
-6
lines changed

4 files changed

+165
-6
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Include jupitern/table in your project, by adding it to your composer.json file.
3333
## Usage
3434
```php
3535
// instance Table with instance name
36-
\Jupitern\Table\Table::instance('dt_example')
36+
\Jupitern\Table\Table::instance()
3737

3838
// set data for non ajax requests
3939
// using a array
@@ -44,7 +44,7 @@ Include jupitern/table in your project, by adding it to your composer.json file.
4444
['id' => 2, 'name' => 'John', 'age' => '44', 'phone' => '169 853 741'],
4545
])
4646
// using json string
47-
->setData('[[1,"Peter","35","961 168 851"],[2,"John","44","169 853 741"]]')
47+
->setData([[1,"Peter","35","961 168 851"],[2,"John","44","169 853 741"]])
4848
// using PDO result or your framework ORM. see example how to grab $data at the end
4949
->setData($data)
5050

@@ -138,7 +138,7 @@ $data = $db->query("SELECT id, name, age, phone FROM persons")->fetchAll(PDO::FE
138138
// used for column filter
139139
$filterData = $db->query("SELECT name as val, name FROM persons limit 10")->fetchAll(PDO::FETCH_OBJ);
140140

141-
\Jupitern\Table\Table::instance('dt_example')
141+
\Jupitern\Table\Table::instance()
142142
->setData($data)
143143
->attr('id', 'demoTable')
144144
->attr('class', 'table table-bordered table-striped table-hover')
@@ -176,7 +176,7 @@ $filterData = $db->query("SELECT name as val, name FROM persons limit 10")->fetc
176176
->render();
177177
?>
178178

179-
Jquery and Datatables should be included.
179+
Include Jquery, Datatables and Bootstrap (optional) in your html.
180180

181181
<!-- JQUERY -->
182182
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
@@ -190,6 +190,14 @@ Jquery and Datatables should be included.
190190
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet">
191191
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
192192

193+
<script type="text/javascript">
194+
195+
$(document).ready(function(){
196+
$('#demoTable').DataTable();
197+
});
198+
199+
</script>
200+
193201
```
194202

195203
## Roadmap

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name" : "jupitern/table",
3-
"description": "php table generation. integrates with your favourite orm and js library",
4-
"keywords" : ["table generation", "framework", "ORM", "dataTables", "jQuery", "UI"],
3+
"description": "HTML table generation for PHP. integrates with your favourite orm and js library",
4+
"keywords" : ["PHP html table generation", "framework", "ORM", "dataTables", "jQuery", "UI"],
55
"homepage" : "https://github.com/jupitern/table",
66
"license" : "MIT",
77
"authors" : [

src/Examples/test1.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
require '../../vendor/autoload.php';
4+
5+
$table = \Jupitern\Table\Table::instance()
6+
->setData([
7+
['id' => 1, 'name' => 'Peter', 'age' => '35', 'phone' => '961 168 851'],
8+
['id' => 2, 'name' => 'John', 'age' => '44', 'phone' => '169 899 742'],
9+
['id' => 3, 'name' => 'Peter', 'age' => '22', 'phone' => '737 853 346'],
10+
['id' => 4, 'name' => 'Clark', 'age' => '34', 'phone' => '169 574 741'],
11+
['id' => 5, 'name' => 'Alex', 'age' => '65', 'phone' => '732 753 467'],
12+
])
13+
->attr('id', 'demoTable')
14+
->attr('class', 'table table-bordered table-striped table-hover')
15+
->attr('cellspacing', '0')
16+
->attr('width', '100%')
17+
->column()
18+
->title('Name')
19+
->value(function ($row) {
20+
return rand(1,10)%2 ? '<b>'.$row['name'].'</b>' : $row['name'];
21+
})
22+
->css('color', 'green')
23+
->css('width', '50%')
24+
->css('background-color', '#ccc', true)
25+
->add()
26+
->column()
27+
->title('Age')
28+
->value('age')
29+
->css('color', 'red')
30+
->css('width', '20%')
31+
->add()
32+
->column('Phone')
33+
->value('phone')
34+
->css('color', 'red')
35+
->css('width', '20%')
36+
->add()
37+
->column()
38+
->value(function ($row) {
39+
return '<a href="country/'. $row['id'] .'">edit</a>';
40+
})
41+
->css('width', '10%')
42+
->add();
43+
?>
44+
45+
46+
<html>
47+
<head>
48+
<!-- JQUERY -->
49+
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
50+
51+
<!-- DATATABLES -->
52+
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet">
53+
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
54+
55+
<!-- Bootstrap and Datatables Bootstrap theme (OPTIONAL) -->
56+
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
57+
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet">
58+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
59+
60+
<script type="text/javascript">
61+
62+
$(document).ready(function(){
63+
$('#demoTable').DataTable();
64+
});
65+
66+
</script>
67+
</head>
68+
<body>
69+
<div style="width: 50%; margin: 30px;">
70+
<?php $table->render(); ?>
71+
</div>
72+
</body>
73+
</html>

src/Examples/test2.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
require '../../vendor/autoload.php';
4+
5+
// grab data from db with PDO or in alternative from your framework ORM
6+
$db = new PDO('mysql:host=HOST_NAME;dbname=DB_NAME;charset=utf8', 'DB_USERNAME', 'DB_PASSWORD',
7+
array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
8+
);
9+
// data to populate table
10+
$data = $db->query("SELECT id, name, age, phone FROM persons")->fetchAll(PDO::FETCH_OBJ);
11+
// used for column filter
12+
$filterData = $db->query("SELECT name as val, name FROM persons limit 10")->fetchAll(PDO::FETCH_OBJ);
13+
14+
\Jupitern\Table\Table::instance()
15+
->setData($data)
16+
->attr('id', 'demoTable')
17+
->attr('class', 'table table-bordered table-striped table-hover')
18+
->attr('cellspacing', '0')
19+
->attr('width', '100%')
20+
->column()
21+
->title('Name')
22+
->value(function ($row) {
23+
return rand(1,10)%2 ? '<b>'.$row['name'].'</b>' : $row['name'];
24+
})
25+
->filter($filterData)
26+
->css('color', 'green')
27+
->css('width', '50%')
28+
->css('background-color', '#ccc', true)
29+
->add()
30+
->column()
31+
->title('Age')
32+
->value('age')
33+
->filter()
34+
->css('color', 'red')
35+
->css('width', '20%')
36+
->add()
37+
->column('Phone')
38+
->filter()
39+
->value('phone')
40+
->css('color', 'red')
41+
->css('width', '20%')
42+
->add()
43+
->column()
44+
->value(function ($row) {
45+
return '<a href="country/'. $row['id'] .'">edit</a>';
46+
})
47+
->css('width', '10%')
48+
->add()
49+
?>
50+
51+
<html>
52+
<head>
53+
<!-- JQUERY -->
54+
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
55+
56+
<!-- DATATABLES -->
57+
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet">
58+
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
59+
60+
<!-- Bootstrap and Datatables Bootstrap theme (OPTIONAL) -->
61+
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
62+
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet">
63+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
64+
65+
<script type="text/javascript">
66+
67+
$(document).ready(function(){
68+
$('#demoTable').DataTable();
69+
});
70+
71+
</script>
72+
</head>
73+
<body>
74+
<div style="width: 50%; margin: 30px;">
75+
<?php $table->render(); ?>
76+
</div>
77+
</body>
78+
</html>

0 commit comments

Comments
 (0)