{"id":18929457,"url":"https://github.com/thecodingmachine/html.widgets.statsgrid","last_synced_at":"2025-04-15T15:30:59.708Z","repository":{"id":4404000,"uuid":"5541292","full_name":"thecodingmachine/html.widgets.statsgrid","owner":"thecodingmachine","description":"This PHP package contains a HTML pivot table. You provide it with a data set and the list of columns and rows and it will display a nice pivot table.","archived":false,"fork":false,"pushed_at":"2024-03-04T08:01:58.000Z","size":135,"stargazers_count":23,"open_issues_count":3,"forks_count":10,"subscribers_count":3,"default_branch":"1.0","last_synced_at":"2025-04-01T18:02:10.524Z","etag":null,"topics":[],"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/thecodingmachine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-08-24T14:24:35.000Z","updated_at":"2025-03-06T13:59:50.000Z","dependencies_parsed_at":"2024-11-08T11:36:03.851Z","dependency_job_id":"7cc777be-2a8c-4cc9-aa77-e0559901fc97","html_url":"https://github.com/thecodingmachine/html.widgets.statsgrid","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":"0.15000000000000002","last_synced_commit":"de700f898884efdf7454715e7b1c5a0b07ae8fb0"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fhtml.widgets.statsgrid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fhtml.widgets.statsgrid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fhtml.widgets.statsgrid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Fhtml.widgets.statsgrid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/html.widgets.statsgrid/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248358748,"owners_count":21090422,"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":[],"created_at":"2024-11-08T11:32:51.651Z","updated_at":"2025-04-15T15:30:59.453Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"StatsGrid: a PHP pivot table\n============================\n\nStatsGrid is a PHP library that let's you generate HTML pivot tables from any dataset.\nYou give the data to be rendered as an array to StatsGrid and it will render the HTML. For instance, you can\ngive this array:\n\n```php\n$data = array(\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"Chicago\", \"year\"=\u003e2009, \"month\"=\u003e\"February\", \"sales\"=\u003e12, \"profit\"=\u003e2),\t\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"Chicago\", \"year\"=\u003e2009, \"month\"=\u003e\"April\", \"sales\"=\u003e12, \"profit\"=\u003e2),\t\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"NY\", \"year\"=\u003e2009, \"month\"=\u003e\"May\", \"sales\"=\u003e15, \"profit\"=\u003e5),\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"Baltimore\", \"year\"=\u003e2009, \"month\"=\u003e\"April\", \"sales\"=\u003e42, \"profit\"=\u003e3),\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"Baltimore\", \"year\"=\u003e2010, \"month\"=\u003e\"April\", \"sales\"=\u003e24, \"profit\"=\u003e4),\n\tarray(\"country\"=\u003e\"FR\", \"city\"=\u003e\"Paris\", \"year\"=\u003e2010, \"month\"=\u003e\"May\", \"sales\"=\u003e12, \"profit\"=\u003e2),\n\tarray(\"country\"=\u003e\"FR\", \"city\"=\u003e\"Paris\", \"year\"=\u003e2010, \"month\"=\u003e\"June\", \"sales\"=\u003e12, \"profit\"=\u003e2),\t\n);\n```\n\t\nand StatsGrid can generate this kind of reports:\n\n\u003ctable class='bluestatsgrid'\u003e\u003ctr\u003e\n\u003ctd\u003e\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd colspan='6' class='header column0'\u003e2009\u003c/td\u003e\u003ctd colspan='6' class='header column0'\u003e2010\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003e\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd colspan='2' class='header column1'\u003eFebruary\u003c/td\u003e\u003ctd colspan='2' class='header column1'\u003eApril\u003c/td\u003e\u003ctd colspan='2' class='header column1'\u003eMay\u003c/td\u003e\u003ctd colspan='2' class='header column1'\u003eApril\u003c/td\u003e\u003ctd colspan='2' class='header column1'\u003eMay\u003c/td\u003e\u003ctd colspan='2' class='header column1'\u003eJune\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003e\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd class='header column2'\u003eSales\u003c/td\u003e\u003ctd class='header column2'\u003eProf.\u003c/td\u003e\u003ctd class='header column2'\u003eSales\u003c/td\u003e\u003ctd class='header column2'\u003eProf.\u003c/td\u003e\u003ctd class='header column2'\u003eSales\u003c/td\u003e\u003ctd class='header column2'\u003eProf.\u003c/td\u003e\u003ctd class='header column2'\u003eSales\u003c/td\u003e\u003ctd class='header column2'\u003eProf.\u003c/td\u003e\u003ctd class='header column2'\u003eSales\u003c/td\u003e\u003ctd class='header column2'\u003eProf.\u003c/td\u003e\u003ctd class='header column2'\u003eSales\u003c/td\u003e\u003ctd class='header column2'\u003eProf.\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd rowspan='3' class='header row0'\u003eUS\u003c/td\u003e\u003ctd class='header row1'\u003eChicago\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e12\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e2\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e12\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e2\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd class='header row1'\u003eNY\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e15\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e5\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd class='header row1'\u003eBaltimore\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e42\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e3\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e24\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e4\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd class='header row0'\u003eFR\u003c/td\u003e\u003ctd class='header row1'\u003eParis\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e12\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e2\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e12\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e2\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nInstalling StatsGrid:\n---------------------\n\nStatsGrid comes as a composer package (the name of the package is *mouf/html.widgets.statsgrid*)\n\nNot used to Composer? The first step is installing Composer. \nThis is essentially a one line process:\n\n```bash\ncurl -s https://getcomposer.org/installer | php\n```\n\nWindows users can download the phar file here: [http://getcomposer.org/download/](install composer).\nThen create a *composer.json* file at the root of your project:\n\n```json\n{\n    \"require\": {\n        \"mouf/html.widgets.statsgrid\": \"~1.0\"\n    }\n}\n```\n\nand finally, run\n\n```bash\nphp composer.phar install\n```\n\n\nUsage sample:\n-------------\n\nTo generate a statsgrid, you need several things:\n- obviously, a dataset (the raw data that you will render)\n- you will also need a set of row and a set of column descriptors (describing what should be in row and what should be in column)\n- finally, you need to decide what values are to be displayed in the grid\n\nStatsGrid is compatible with [Mouf](http://mouf-php.com) so you can completely define a grid using Mouf's graphical interface.\n\nNot using [Mouf](http://mouf-php.com)? You should! But here is a sample code base anyway:\n\n```php\n// Let's load the autoloader\nrequire 'vendor/autoload.php';\n\n// Let's import all required classes\nuse Mouf\\Html\\Widgets\\StatsGrid\\StatsGrid;\nuse Mouf\\Html\\Widgets\\StatsGrid\\StatsColumnDescriptor;\nuse Mouf\\Html\\Widgets\\StatsGrid\\StatsValueDescriptor;\nuse Mouf\\Html\\Widgets\\StatsGrid\\Aggregate\\SumAggregator;\n\n// Let's define the data to be displayed (usually, you will get this from a database using GROUP BY statements)\n$data = array(\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"Chicago\", \"year\"=\u003e2009, \"month\"=\u003e\"February\", \"sales\"=\u003e12, \"profit\"=\u003e2),\t\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"Chicago\", \"year\"=\u003e2009, \"month\"=\u003e\"April\", \"sales\"=\u003e12, \"profit\"=\u003e2),\t\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"NY\", \"year\"=\u003e2009, \"month\"=\u003e\"May\", \"sales\"=\u003e15, \"profit\"=\u003e5),\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"Baltimore\", \"year\"=\u003e2009, \"month\"=\u003e\"April\", \"sales\"=\u003e42, \"profit\"=\u003e3),\n\tarray(\"country\"=\u003e\"US\", \"city\"=\u003e\"Baltimore\", \"year\"=\u003e2010, \"month\"=\u003e\"April\", \"sales\"=\u003e24, \"profit\"=\u003e4),\n\tarray(\"country\"=\u003e\"FR\", \"city\"=\u003e\"Paris\", \"year\"=\u003e2010, \"month\"=\u003e\"May\", \"sales\"=\u003e12, \"profit\"=\u003e2),\n\tarray(\"country\"=\u003e\"FR\", \"city\"=\u003e\"Paris\", \"year\"=\u003e2010, \"month\"=\u003e\"June\", \"sales\"=\u003e12, \"profit\"=\u003e2),\t\n);\n\n// The StatsGrid object is the main object used to display the grid\n$grid = new StatsGrid();\n\n// Let's associate the data to the grid\n$grid-\u003esetData($data);\n\n// Now, let's define 2 row descriptors: COUNTRY and CITY\n$countryRow = new StatsColumnDescriptor(\"country\");\n$cityRow = new StatsColumnDescriptor(\"city\");\n// We associate these column descriptors to the grid\n$grid-\u003eaddRow($countryRow);\n$grid-\u003eaddRow($cityRow);\n\n\n// Now, let's define 2 column descriptors: YEAR and MONTH\n$yearColumn = new StatsColumnDescriptor(\"year\");\n$monthColumn = new StatsColumnDescriptor(\"month\");\n// Do not sort the month column alphabetically (see sorting paragraph below)\n$monthColumn-\u003esetSort(false);\n// We associate these column descriptors to the grid\n$grid-\u003eaddColumn($yearColumn);\n$grid-\u003eaddColumn($monthColumn);\n\n// Let's define the values to be displayed in the table\n$salesValue = new StatsValueDescriptor(\"sales\", \"Sales\");\n$grid-\u003eaddValue($salesValue);\n\n// Finally, let's print the table\n$grid-\u003etoHtml();\n```\n\nAdding aggregation (sums/means...):\n-----------------------------------\n\nPresenting data in a pivot table is nice, but often, you will find out you want to display sums or means of the data at the bottom of the table.\nStatsGrid let's you *aggregate* data (performing sums/means...) on any column or any row. This way, you can perform sums / subsums, etc... the way you want.\n\nIn order to aggregate data, you just need to call the addAggregator method and pass a valid aggregator object.\n\n```php\n// Let's add 4 aggregators (sub and subsums on columns and on rows)\n$grid-\u003eaddAggregator(new SumAggregator($countryRow, $salesValue, \"Total Sales\"));\n$grid-\u003eaddAggregator(new SumAggregator($cityRow, $salesValue, \"Total city\"));\n$grid-\u003eaddAggregator(new SumAggregator($monthColumn, $salesValue, \"Total month\"));\n$grid-\u003eaddAggregator(new SumAggregator($yearColumn, $salesValue, \"Total year\"));\n```\n \nIn the sample above we decide we want to sum data by country/city and year/month.\nTherefore, we create 4 SumAggregator objects.\nFor each aggregator we need:\n- The column/row we will be summing upon\n- The object representing the value we will be summing\n- The title of the aggregator\n\nBy just adding those 4 lines, we will get this:\n\n\u003ctable class='bluestatsgrid'\u003e\u003ctr\u003e\n\u003ctd\u003e\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd colspan='4' class='header column0'\u003e2009\u003c/td\u003e\u003ctd colspan='4' class='header column0'\u003e2010\u003c/td\u003e\u003ctd class='header column0'\u003eTotal year\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003e\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd class='header column1'\u003eFebruary\u003c/td\u003e\u003ctd class='header column1'\u003eApril\u003c/td\u003e\u003ctd class='header column1'\u003eMay\u003c/td\u003e\u003ctd class='header column1'\u003eTotal month\u003c/td\u003e\u003ctd class='header column1'\u003eApril\u003c/td\u003e\u003ctd class='header column1'\u003eMay\u003c/td\u003e\u003ctd class='header column1'\u003eJune\u003c/td\u003e\u003ctd class='header column1'\u003eTotal month\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd rowspan='4' class='header row0'\u003eUS\u003c/td\u003e\u003ctd class='header row1'\u003eChicago\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e12\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e12\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columneven'\u003e24\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columneven'\u003e0\u003c/td\u003e\u003ctd class='aggregate0 value roweven columneven'\u003e24\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd class='header row1'\u003eNY\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e15\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e15\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='value rowodd columnodd'\u003e\u003c/td\u003e\u003ctd class='value roweven columnodd'\u003e\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e0\u003c/td\u003e\u003ctd class='aggregate0 value roweven columnodd'\u003e15\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd class='header row1'\u003eBaltimore\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e42\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columneven'\u003e42\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e24\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columneven'\u003e24\u003c/td\u003e\u003ctd class='aggregate0 value roweven columneven'\u003e66\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd class='header row1'\u003eTotal city\u003c/td\u003e\u003ctd class='aggregate1 value roweven columnodd'\u003e12\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e54\u003c/td\u003e\u003ctd class='aggregate1 value roweven columnodd'\u003e15\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e81\u003c/td\u003e\u003ctd class='aggregate1 value roweven columnodd'\u003e24\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e0\u003c/td\u003e\u003ctd class='aggregate1 value roweven columnodd'\u003e0\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e24\u003c/td\u003e\u003ctd class='aggregate0 value roweven columnodd'\u003e105\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd rowspan='2' class='header row0'\u003eFR\u003c/td\u003e\u003ctd class='header row1'\u003eParis\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columneven'\u003e0\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e\u003c/td\u003e\u003ctd class='value rowodd columneven'\u003e12\u003c/td\u003e\u003ctd class='value roweven columneven'\u003e12\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columneven'\u003e24\u003c/td\u003e\u003ctd class='aggregate0 value roweven columneven'\u003e24\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd class='header row1'\u003eTotal city\u003c/td\u003e\u003ctd class='aggregate1 value roweven columnodd'\u003e0\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e0\u003c/td\u003e\u003ctd class='aggregate1 value roweven columnodd'\u003e0\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e0\u003c/td\u003e\u003ctd class='aggregate1 value roweven columnodd'\u003e0\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e12\u003c/td\u003e\u003ctd class='aggregate1 value roweven columnodd'\u003e12\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columnodd'\u003e24\u003c/td\u003e\u003ctd class='aggregate0 value roweven columnodd'\u003e24\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd class='header row0'\u003eTotal Sales\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd class='aggregate0 value roweven columneven'\u003e12\u003c/td\u003e\u003ctd class='aggregate0 value rowodd columneven'\u003e54\u003c/td\u003e\u003ctd class='aggregate0 value roweven columneven'\u003e15\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columneven'\u003e81\u003c/td\u003e\u003ctd class='aggregate0 value roweven columneven'\u003e24\u003c/td\u003e\u003ctd class='aggregate0 value rowodd columneven'\u003e12\u003c/td\u003e\u003ctd class='aggregate0 value roweven columneven'\u003e12\u003c/td\u003e\u003ctd class='aggregate1 value rowodd columneven'\u003e48\u003c/td\u003e\u003ctd class='aggregate0 value roweven columneven'\u003e129\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nDisplaying several values:\n--------------------------\n\nIf you look at the dataset we have been working on, we have 2 sets of values: \"sales\" and \"profit\".\nSo far, we have been displaying only the \"sales\" value. However, stats grid can perfectly handle displaying 2 values next to each other.\n\nFor instance, you could write:\n\n```php\n// Let's define the values to be displayed in the table\n$salesValue = new StatsValueDescriptor(\"sales\", \"Sales\");\n$profitValue = new StatsValueDescriptor(\"profit\", \"Prof.\");\n$grid-\u003eaddValue($salesValue);\n$grid-\u003eaddValue($profitValue);\n```\n\nThis will displays The 2 values in 2 columns.\nIf you want values to be displayed in rows rather in column, just add:\n\n```php\n// There are several value descriptor, let's put those in rows.\n$grid-\u003esetValuesDisplayMode(StatsGrid::VALUES_DISPLAY_VERTICAL);\n```\n\nSorting columns/rows headers\n----------------------------\n\nIn the exemple above, the years are sorted numerically (2009, 2010...)\nHowever, we might very well want to alter this order. Maybe we want to store the result in reverse order.\nOr maybe we want the result not to be sorted at all (and be displayed in the order of the origin dataset).\n\nFor these use case, there is the `setSort` method. This function takes a boolean (`true`|`false`), or\na callable function that will be called to compare 2 items (just like the `usort` PHP function).\n\nHere is an example to sort the columns in reverse order:\n\n```php\n// Let's sort the YEAR columns in reverse order (2010, 2009...)\n$yearColumn-\u003esetSort(function($a, $b) { return  $b-$a; });\n```\n\n\nStyling statsgrids:\n-------------------\n\nStatsgrid comes with a default CSS stylesheet.\nYou can find it in *css/dist/statsgrid.css*.\n\nUsing composer? Add this to your theme:\n\n```html\n\u003clink rel=\"stylesheet\" type=\"text/css\" href=\"[myproject]/vendor/mouf/html.widgets.statsgrid/css/dist/statsgrid.css\" /\u003e\n```\n\nBy default the grid is in blueish tones.\n\nYou can change the main CSS class of the grid using:\n```php\n// Changes the design of the grid\n$grid-\u003esetCssClass(\"redstatsgrid\");\n```\n\nThose are valid CSS classes defined in the statsgrid package:\n- bluestatsgrid\n- redstatsgrid\n- greenstatsgrid\n- greystatsgrid\n- yellowstatsgrid\n- purplestatsgrid\n- cyanstatsgrid\n\nYou can of course provide your own class to suit your needs.\nThe *css/src/statsgrid.scss* file contains the [SASS file](http://sass-lang.com/) that has been used to generate those themes easily.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fhtml.widgets.statsgrid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Fhtml.widgets.statsgrid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Fhtml.widgets.statsgrid/lists"}