{"id":17492125,"url":"https://github.com/jupitern/table","last_synced_at":"2025-04-22T20:16:08.500Z","repository":{"id":26149446,"uuid":"29594607","full_name":"jupitern/table","owner":"jupitern","description":"a fluent HTML table generation with PHP. Framework agnostic","archived":false,"fork":false,"pushed_at":"2022-06-30T21:22:22.000Z","size":55,"stargazers_count":23,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-22T20:16:03.368Z","etag":null,"topics":["html-table","php","php-table","table","table-generator"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jupitern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-21T14:55:58.000Z","updated_at":"2025-01-30T16:23:55.000Z","dependencies_parsed_at":"2022-08-01T06:08:32.703Z","dependency_job_id":null,"html_url":"https://github.com/jupitern/table","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupitern%2Ftable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupitern%2Ftable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupitern%2Ftable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jupitern%2Ftable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jupitern","download_url":"https://codeload.github.com/jupitern/table/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250316066,"owners_count":21410476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html-table","php","php-table","table","table-generator"],"created_at":"2024-10-19T08:08:02.123Z","updated_at":"2025-04-22T20:16:08.480Z","avatar_url":"https://github.com/jupitern.png","language":"PHP","readme":"[![Build Status](https://scrutinizer-ci.com/g/jupitern/table/badges/build.png?b=master)](https://scrutinizer-ci.com/g/jupitern/table/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jupitern/table/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jupitern/table/?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/jupitern/table/v/stable.svg)](https://packagist.org/packages/jupitern/table) [![Latest Unstable Version](https://poser.pugx.org/jupitern/table/v/unstable.svg)](https://packagist.org/packages/jupitern/table) [![License](https://poser.pugx.org/jupitern/table/license.svg)](https://packagist.org/packages/jupitern/table)\n# jupitern/table\n#### HTML table generation with PHP.\n\nPass your data using:\n* JSON, Arrays (associative or not).\n* result set using PDO or you favourite framework ORM.\n* directly or using ajax requests.\n* Integrates easily with your preferred js library.\n* more to come...\n\n## Demo:\n\nsoon...\n\n## Requirements\n\nPHP 8.0 or higher.\n\n## Installation\n\nInclude jupitern/table in your project, by adding it to your composer.json file.\n```php\n{\n    \"require\": {\n        \"jupitern/table\": \"3.*\"\n    }\n}\n```\n\n## Usage\n```php\n// instance Table with instance name\n\\Jupitern\\Table\\Table::instance()\n\n// set data for non ajax requests\n// using a array\n-\u003esetData([ [1, 'Peter', '35', '961 168 851'], [2, 'John', '44', '169 853 741'] ])\n// using a associative array\n-\u003esetData([\n\t['id' =\u003e 1, 'name' =\u003e 'Peter', 'age' =\u003e '35', 'phone' =\u003e '961 168 851'],\n\t['id' =\u003e 2, 'name' =\u003e 'John', 'age' =\u003e '44', 'phone' =\u003e '169 853 741'],\n])\n// using json string\n-\u003esetData([[1,\"Peter\",\"35\",\"961 168 851\"],[2,\"John\",\"44\",\"169 853 741\"]])\n// using PDO result or your framework ORM. see example how to grab $data at the end\n-\u003esetData($data)\n\n// add attributes to the \u003ctable\u003e html tag one by one\n-\u003eattr('table', 'id', 'demoTable')\n-\u003eattr('table', 'class', 'table table-bordered table-striped table-hover')\n-\u003eattr('table', 'cellspacing', '0')\n\n// or add all \u003ctable\u003e attributes at once\n-\u003eattrs('table', ['class' =\u003e 'table table-bordered', 'cellspacing' =\u003e '0'])\n\n// add attributes to the table rows\n-\u003ecss('tr', 'background-color', 'red')\n\n// add attributes to the table rows using a callable\n-\u003eattr('tr', 'data-id', function($row) {\n    return 'row-' . $row['id'];\n})\n\n// add a new column for array data\n-\u003ecolumn()\n\t-\u003etitle('Name')\n\t-\u003evalue(1)\n-\u003eadd()\n\n// add a new column for (associative array, PDO or ORM) data\n-\u003ecolumn()\n\t-\u003etitle('Age')\n\t-\u003evalue('age')\n-\u003eadd()\n\n// add a column with a closure for value field to process data in execution\n// this example assumes data as object\n-\u003ecolumn()\n\t-\u003etitle('Name')\n\t-\u003evalue(function ($row) {\n\t\treturn rand(1,10)%2 ? '\u003cb\u003e'.$row-\u003ename.'\u003c/b\u003e' : $row-\u003ename;\n\t})\n-\u003eadd()\n\n// another closure example for adding a column with edit action with no title on \u003cth\u003e\n// this example assumes data associative array\n-\u003ecolumn()\n\t-\u003evalue(function ($row) {\n\t\treturn '\u003ca href=\"edit/'.$row['id'].'\"\u003eedit '.$row['name'].'\u003c/a\u003e';\n\t})\n-\u003eadd()\n\n// add a column with text field as filter\n-\u003ecolumn()\n\t-\u003etitle('Name')\n\t-\u003evalue('name')\n\t-\u003efilter()\n-\u003eadd()\n\n// add a column with a drop down field as filter\n// $filterData as array\n-\u003ecolumn()\n\t-\u003etitle('Name')\n\t-\u003evalue('name')\n\t-\u003efilter([[1, 'Peter'], [2, 'John']])\n-\u003eadd()\n\n// add a column with a drop down field as filter\n// $filterData from (associtive array, PDO or ORM). see example how to grab $data at the end\n-\u003ecolumn()\n\t-\u003etitle('Name')\n\t-\u003evalue('name')\n\t-\u003efilter($filterData)\n-\u003eadd()\n\n// add a column with some attributes and css for \u003cth\u003e and \u003ctd\u003e\n-\u003ecolumn()\n\t-\u003etitle('Name')\n\t-\u003evalue('name')\n\t-\u003eattr('th', 'data-val', 'foo')\t\t        // add attributes to \u003cth\u003e\n    -\u003ecss('th', 'background-color', '#f5f5f5')\t// add css to \u003cth\u003e\n    -\u003eattr('td', 'data-val', 'bar')\t\t\t\t// add attributes to \u003ctd\u003e\n    -\u003ecss('td', 'background-color', '#f5f5f5')\t// add css to \u003ctd\u003e\n-\u003eadd()\n\n// echo table output\n-\u003erender();\n\n// OR return table output\n-\u003erender(true);\n\n```\n\n\n## Example using PDO and datatables\n```php\n// grab data from db with PDO or in alternative from your framework ORM\n$db = new PDO('mysql:host=HOST_NAME;dbname=DB_NAME;charset=utf8', 'DB_USERNAME', 'DB_PASSWORD',\n\t\tarray(PDO::ATTR_EMULATE_PREPARES =\u003e false, PDO::ATTR_ERRMODE =\u003e PDO::ERRMODE_EXCEPTION)\n);\n// data to populate table\n$data = $db-\u003equery(\"SELECT id, name, age, phone FROM persons\")-\u003efetchAll(PDO::FETCH_OBJ);\n// used for column filter\n$filterData = $db-\u003equery(\"SELECT name as val, name FROM persons limit 10\")-\u003efetchAll(PDO::FETCH_OBJ);\n\n\\Jupitern\\Table\\Table::instance()\n\t-\u003esetData($data)\n\t-\u003eattr('table', 'id', 'demoTable')\n\t-\u003eattr('table', 'class', 'table table-bordered table-striped table-hover')\n\t-\u003eattr('table', 'cellspacing', '0')\n\t-\u003eattr('table', 'width', '100%')\n\t-\u003ecolumn()\n\t\t-\u003etitle('Name')\n\t\t-\u003evalue(function ($row) {\n\t\t\treturn rand(1,10)%2 ? '\u003cb\u003e'.$row-\u003ename.'\u003c/b\u003e' : $row-\u003ename;\n\t\t})\n\t\t-\u003efilter($filterData)\n\t\t-\u003ecss('td', 'color', 'green')\n\t\t-\u003ecss('td', 'width', '50%')\n\t\t-\u003ecss('td', 'background-color', '#ccc', true)\n\t-\u003eadd()\n\t-\u003ecolumn()\n\t\t-\u003etitle('Age')\n\t\t-\u003evalue('age')\n\t\t-\u003efilter()\n\t\t-\u003ecss('td', 'color', 'red')\n\t\t-\u003ecss('td', 'width', '20%')\n\t-\u003eadd()\n\t-\u003ecolumn()\n\t    -\u003etitle('Phone')\n\t\t-\u003efilter()\n\t\t-\u003evalue('phone')\n\t\t-\u003ecss('td', 'color', 'red')\n\t\t-\u003ecss('td', 'width', '20%')\n\t-\u003eadd()\n\t-\u003ecolumn()\n\t\t-\u003evalue(function ($row) {\n\t\t\treturn '\u003ca href=\"country/'.$row-\u003eid.'\"\u003eedit\u003c/a\u003e';\n\t\t})\n\t\t-\u003ecss('td', 'width', '10%')\n\t-\u003eadd()\n\t-\u003erender();\n?\u003e\n\nInclude Jquery, Datatables and Bootstrap (optional) in your html.\n\n\u003c!-- JQUERY --\u003e\n\u003cscript\n    src=\"https://code.jquery.com/jquery-3.6.0.slim.min.js\"\n    integrity=\"sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=\"\n    crossorigin=\"anonymous\"\u003e\u003c/script\u003e\n\n\u003c!-- DATATABLES --\u003e\n\u003clink href=\"//cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css\" rel=\"stylesheet\"\u003e\n\u003cscript src=\"//cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js\"\u003e\u003c/script\u003e\n\n\u003c!-- Bootstrap and Datatables Bootstrap theme (OPTIONAL) --\u003e\n\u003clink href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" rel=\"stylesheet\"\u003e\n\u003clink href=\"https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css\" rel=\"stylesheet\"\u003e\n\u003cscript src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"\u003e\u003c/script\u003e\n        \n\u003cscript type=\"text/javascript\"\u003e\n    $(document).ready( function () {\n        $('#demoTable').DataTable();\n    });\n\u003c/script\u003e\n\n```\n\n## Roadmap\n\n - [ ] add demo and more examples\n - [ ] code some tests\n\n## Contributing\n\n - welcome to discuss a bugs, features and ideas.\n\n## License\n\njupitern/table is release under the MIT license.\n\nYou are free to use, modify and distribute this software, as long as the copyright header is left intact\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupitern%2Ftable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjupitern%2Ftable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjupitern%2Ftable/lists"}