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
|
|
|
// ->attrs('table', ['class' => 'table table-bordered', 'cellspacing' => '0']) |
14
|
|
|
->attr('table', 'id', 'demoTable') |
15
|
|
|
->attr('table', 'class', 'table table-bordered table-striped table-hover') |
16
|
|
|
->attr('table', 'cellspacing', '0') |
17
|
|
|
->attr('table', 'width', '100%') |
18
|
|
|
->attr('tr', 'data-text', 'bla bla bla bla bla') |
19
|
|
|
->attr('tr', 'data-id', function($row) { |
20
|
|
|
return 'row-' . $row['id']; |
21
|
|
|
}) |
22
|
|
|
->css('tr', 'background-color', 'red') |
23
|
|
|
->column() |
24
|
|
|
->title('Name') |
25
|
|
View Code Duplication |
->value(function ($row) { |
|
|
|
|
26
|
|
|
return rand(1,10)%2 ? '<b>'.$row['name'].'</b>' : $row['name']; |
27
|
|
|
}) |
28
|
|
|
->attr('td', 'data-text', 'bla bla bla') |
29
|
|
|
->css('th', 'color', 'green') |
30
|
|
|
->css('td', 'width', '50%') |
31
|
|
|
->css('td', 'background-color', '#ccc') |
32
|
|
|
->add() |
33
|
|
|
->column() |
34
|
|
|
->title('Age') |
35
|
|
|
->value('age') |
36
|
|
|
->css('th', 'color', 'red') |
37
|
|
|
->css('td', 'width', '20%') |
38
|
|
|
->add() |
39
|
|
|
->column('Phone') |
|
|
|
|
40
|
|
|
->value('phone') |
41
|
|
|
->css('td', 'color', 'red') |
42
|
|
|
->css('td', 'width', '20%') |
43
|
|
|
->add() |
44
|
|
|
->column() |
45
|
|
|
->value(function ($row) { |
46
|
|
|
return '<a href="country/'. $row['id'] .'">edit</a>'; |
47
|
|
|
}) |
48
|
|
|
->css('td', 'width', '10%') |
49
|
|
|
->add(); |
50
|
|
|
?> |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
<html> |
54
|
|
|
<head> |
55
|
|
|
<!-- JQUERY --> |
56
|
|
|
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> |
57
|
|
|
|
58
|
|
|
<!-- DATATABLES --> |
59
|
|
|
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet"> |
60
|
|
|
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> |
61
|
|
|
|
62
|
|
|
<!-- Bootstrap and Datatables Bootstrap theme (OPTIONAL) --> |
63
|
|
|
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> |
64
|
|
|
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet"> |
65
|
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> |
66
|
|
|
|
67
|
|
|
<script type="text/javascript"> |
68
|
|
|
|
69
|
|
|
$(document).ready(function(){ |
70
|
|
|
$('#demoTable').DataTable(); |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
</script> |
74
|
|
|
</head> |
75
|
|
|
<body> |
76
|
|
|
<div style="width: 50%; margin: 30px;"> |
77
|
|
|
<?php $table->render(); ?> |
78
|
|
|
</div> |
79
|
|
|
</body> |
80
|
|
|
</html> |
81
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.