class NumericCellRenderer implements RenderCellInterface, FormatterAwareInterface (View source)

Create a formatter to add commas to numeric data.

Example:


Value

 2,384

143,894 23 98,538

This formatter may also be re-used for other purposes where right-justified data is desired by simply making a subclass. See method comments below.

Usage:

return (new RowsOfFields($data))->addRenderer(
     new NumericCellRenderer($data, ['value'])
);

Traits

Properties

protected $formatter from  FormatterAwareTrait
protected $data
protected $renderedColumns
protected $widths

Methods

setFormatter(FormatterInterface $formatter)

No description

getFormatter()

No description

isHumanReadable()

No description

__construct($data, $renderedColumns)

NumericCellRenderer constructor

mixed
renderCell(string $key, mixed $cellData, FormatterOptions $options, array $rowData)

No description

justifyCellData($key, $cellData = "")

Right-justify the cell data.

isRenderedFormat(FormatterOptions $options)

Determine if this format is to be formatted.

isRenderedColumn($key)

Determine if this is a column that should be formatted.

isRenderedData($cellData)

Ignore cell data that should not be formatted.

formatCellData($cellData)

Format the cell data.

convertCellDataToString($cellData)

This formatter only works with columns whose columns are strings.

columnWidth($key)

Get the cached column width for the provided key.

calculateColumnWidth($key)

Using the cached table data, calculate the largest width for the data in the table for use when right-justifying.

Details

setFormatter(FormatterInterface $formatter)

No description

Parameters

FormatterInterface $formatter

getFormatter()

No description

isHumanReadable()

No description

__construct($data, $renderedColumns)

NumericCellRenderer constructor

Parameters

$data
$renderedColumns

mixed renderCell(string $key, mixed $cellData, FormatterOptions $options, array $rowData)

No description

Parameters

string $key

Identifier of the cell being rendered

mixed $cellData

The data to render

FormatterOptions $options

The formatting options

array $rowData

The rest of the row data

Return Value

mixed

protected justifyCellData($key, $cellData = "")

Right-justify the cell data.

Parameters

$key
$cellData

protected isRenderedFormat(FormatterOptions $options)

Determine if this format is to be formatted.

Parameters

FormatterOptions $options

protected isRenderedColumn($key)

Determine if this is a column that should be formatted.

Parameters

$key

protected isRenderedData($cellData)

Ignore cell data that should not be formatted.

Parameters

$cellData

protected formatCellData($cellData)

Format the cell data.

Parameters

$cellData

protected convertCellDataToString($cellData)

This formatter only works with columns whose columns are strings.

To use this formatter for another purpose, override this method to ensure that the cell data is a string before it is formatted.

Parameters

$cellData

protected columnWidth($key)

Get the cached column width for the provided key.

Parameters

$key

protected calculateColumnWidth($key)

Using the cached table data, calculate the largest width for the data in the table for use when right-justifying.

Parameters

$key