{"id":24581387,"url":"https://github.com/andydune/htmltable","last_synced_at":"2025-03-17T16:19:23.130Z","repository":{"id":56948182,"uuid":"180995975","full_name":"AndyDune/HtmlTable","owner":"AndyDune","description":"This code will simplify or improve your work with html tables.","archived":false,"fork":false,"pushed_at":"2020-05-31T15:26:06.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T02:56:10.971Z","etag":null,"topics":["html-table","html-table-generator"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndyDune.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-12T11:38:34.000Z","updated_at":"2020-05-31T15:26:08.000Z","dependencies_parsed_at":"2022-08-21T03:10:17.796Z","dependency_job_id":null,"html_url":"https://github.com/AndyDune/HtmlTable","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyDune%2FHtmlTable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyDune%2FHtmlTable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyDune%2FHtmlTable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyDune%2FHtmlTable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndyDune","download_url":"https://codeload.github.com/AndyDune/HtmlTable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244066191,"owners_count":20392407,"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","html-table-generator"],"created_at":"2025-01-24T02:56:18.652Z","updated_at":"2025-03-17T16:19:23.106Z","avatar_url":"https://github.com/AndyDune.png","language":"PHP","readme":"# HtmlTable\nThis code will simplify or improve your work with html tables.\n\n[![Build Status](https://travis-ci.org/AndyDune/HtmlTable.svg?branch=master)](https://travis-ci.org/AndyDune/HtmlTable)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![Packagist Version](https://img.shields.io/packagist/v/andydune/html-table.svg?style=flat-square)](https://packagist.org/packages/andydune/html-table)\n[![Total Downloads](https://img.shields.io/packagist/dt/andydune/html-table.svg?style=flat-square)](https://packagist.org/packages/andydune/html-table)\n\n\nRequirements\n------------\n\nPHP version \u003e= 5.6\n\nInstallation\n------------\n\nInstallation using composer:\n\n```\ncomposer require andydune/html-table\n```\nOr if composer was not installed globally:\n```\nphp composer.phar require andydune/html-table\n```\nOr edit your `composer.json`:\n```\n\"require\" : {\n     \"andydune/html-table\": \"^1\"\n}\n\n```\nAnd execute command:\n```\nphp composer.phar update\n```\n\nExample\n-----------\n\nHere is small part of code for drawing html table with dynamic data. \n\n```php\n\u003ctable class=\"table authlog\"\u003e\n    \u003cthead\u003e\n    \u003ctr\u003e\n        \u003ctd\u003eID\u003c/td\u003e\n        \u003ctd\u003eUser\u003c/td\u003e\n        \u003ctd\u003eSTATUS\u003c/td\u003e\n        \u003ctd\u003eCreated\u003c/td\u003e\n        \u003ctd\u003eUpdated\u003c/td\u003e\n        \u003ctd\u003eUploaded\u003c/td\u003e\n        \u003ctd\u003eLink\u003c/td\u003e\n        \u003ctd\u003eData\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n    \u003c?php foreach ($list as $file) {\n        ?\u003e\n        \u003ctr class=\"\u003c?= $file-\u003egetStatus() == 2 ? 'table-success' : null; ?\u003e\"\u003e\n            \u003ctd\u003e\u003c?= $file-\u003egetId(); ?\u003e\u003c/td\u003e\n            \u003ctd\u003e\u003c?= $user['EMAIL'] ?\u003e (\u003c?= $user['XML_ID'] ?\u003e)\u003c/td\u003e\n            \u003ctd\u003e\u003c?= $showStatus($file-\u003egetStatus()); ?\u003e\u003c/td\u003e\n            \u003ctd\u003e\u003c?= $file-\u003egetData('DATETIME'); ?\u003e\u003c/td\u003e\n            \u003ctd\u003e\u003c?= $file-\u003egetData('DATETIME_UPDATE'); ?\u003e\u003c/td\u003e\n            \u003ctd\u003e\u003c?= $file-\u003egetData('DATETIME_LAST_REQUEST'); ?\u003e\u003c/td\u003e\n            \u003ctd\u003e\u003c?= $file-\u003egetFileName(); ?\u003e.\u003c?= $file-\u003egetFileType() ?\u003e\u003c/td\u003e\n            \u003ctd\u003e\u003c? $showArray($file-\u003egetMeta()) ?\u003e\u003c/td\u003e\n            \u003ctd\u003e\u003c/td\u003e\n            \u003ctd\u003eповтор\u003c/td\u003e\n            \u003ctd\u003eудаление\u003c/td\u003e\n        \u003c/tr\u003e\n    \u003c?php } ?\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n```\nIt is simple to accidentally break html by removing single tag. And it is difficult to read and change.\n\nThere is better code down below:\n```php\nuse AndyDune\\HtmlTable\\Builder;\nuse AndyDune\\HtmlTable\\Table;\n\n$table = new Table();\n$head = $table-\u003ehead();\n$head-\u003ecell()-\u003esetContent('ID');\n$head-\u003ecell()-\u003esetContent('User');\n$head-\u003ecell()-\u003esetContent('STATUS');\n$head-\u003ecell()-\u003esetContent('Created');\n$head-\u003ecell()-\u003esetContent('Updated');\n$head-\u003ecell()-\u003esetContent('Uploaded');\n$head-\u003ecell()-\u003esetContent('Uploaded');\n$head-\u003ecell()-\u003esetContent('Data');\n// Empty cells will be added automatically depends on max cell count for next rows.\nforeach ($list as $file) {\n    $row = $table-\u003erow();\n    if ($file-\u003egetStatus() == 2) {\n        $row-\u003eaddClass('table-success')\n    }\n    $row-\u003ecell()-\u003esetContent($file-\u003egetId());\n    $row-\u003ecell()-\u003esetContent($user['EMAIL'] . $user['XML_ID']);\n    $row-\u003ecell()-\u003esetContent($showStatus($file-\u003egetStatus()));\n    $row-\u003ecell()-\u003esetContent($file-\u003egetData('DATETIME'));\n    $row-\u003ecell()-\u003esetContent($file-\u003egetData('DATETIME_UPDATE'));\n    $row-\u003ecell()-\u003esetContent($file-\u003egetData('DATETIME_LAST_REQUEST'));\n    $row-\u003ecell()-\u003esetContent($file-\u003egetFileName() . '.' . $file-\u003egetFileType());\n    $row-\u003ecell()-\u003esetContent($showArray($file-\u003egetMeta()));\n}\n\n$buider = new Builder($table);\n$builder-\u003esetGroupingSections(true);\necho $buider-\u003egetHtml(); \n``` \n\nClass structure\n----------\n\nTable structure is reflect by classes:\n\n- `AndyDune\\HtmlTable\\Table` - a root of the structure\n- `AndyDune\\HtmlTable\\Element\\Row` - it implements a table row \n- `AndyDune\\HtmlTable\\Element\\Head` - it implements a special table row (head). It can be only one. \n- `AndyDune\\HtmlTable\\Element\\Cell` - it implements a table cell. It is a part of `Row` (`Head`)\n\n- `AndyDune\\HtmlTable\\Builder` - the root class for building html code for table. \nIt receives `Table` instance as a construct parameter.  \n\n- There are many assistive classes for building table, but you don't need to know about their.\n\nDescribe table\n-------\n\nTable may have attributes, data rows, head row. Rows and cells may have attributes too.\n\n### Table, row, cell class attribute\n\nUse method `addClass` to inject class into table element. Element may have many classes:\n\n```php\nuse AndyDune\\HtmlTable\\Table;\n\n// Set classes *useful* and  *one* to table.\n$table = new Table();\n$table-\u003eaddClass('useful')-\u003eaddClass('one');\n$table-\u003egetClasses(); ['useful', 'one]\n// \u003ctable class=\"useful one\"\u003e\n\n// Set class *active* to row.\n$row = $table-\u003erow();\n$row-\u003eaddClass('active');\n// \u003ctr class=\"active\"\u003e\n\n// Set class *left* to cell.\n$cell = $row-\u003ecell();\n$row-\u003eaddClass('left');\n// \u003ctd class=\"left\"\u003e\n```  \n\n### Table, row, cell id attribute\n\nUse method `setId` to inject id into table element. Element may have only one id:\n\n```php\nuse AndyDune\\HtmlTable\\Table;\n\n// \u003ctable id=\"top\"\u003e\n$table = new Table();\n$table-\u003esetId('top');\n$table-\u003egetId(); // top\n\n// \u003ctr id=\"active\"\u003e\n$row = $table-\u003erow();\n$row-\u003esetId('active');\n$row-\u003egetId(); // active\n\n// \u003ctd id=\"left\"\u003e\n$cell = $row-\u003ecell();\n$row-\u003esetId('left');\n$row-\u003egetId(); //left\n```  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandydune%2Fhtmltable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandydune%2Fhtmltable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandydune%2Fhtmltable/lists"}