KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

How to relabel column name containing numbers? #44

Open zenon opened this topic on on Jul 31, 2017 - 8 comments

zenon commented on Jul 31, 2017

Hi,

How can I relabel this column name? I'm using ColumnMeta. I got a syntax error.

"date("2017-07-01")"=>array(
    "label"=>"datefrom"),

Thanks.

KoolReport commented on Jul 31, 2017

ColumnMeta is used to set meta data for one or more than one columns:

->pipe(new ColumnMeta(array(
    "my_column_name"=>array(
        "label"=>"My Column Name",
    )
)))

Remember name of column is different from label of column. Label is a nice name which is normally used to display.

zenon commented on Jul 31, 2017

The column name is the result of the query. How could I label the column name? I want to label as datefrom and dateto.

The column name contain numbers, which is date. If I do as above, this will result in an error. However, other columns which contains only alphabets were able to work.

Thanks.

KoolReport commented on Jul 31, 2017

You may try to do this:

->pipe(new ColumnMeta(array(
    'date("2017-07-01")'=>array(
        "name"=>"date_form", //Rename the column name
    )
)))

Note: Use the single quote

Why do you need to name the column in a "hard" way like this? May I view your SQL statement or source of data?

zenon commented on Jul 31, 2017

Thanks. I managed to do it. I could not change the SQL statement. Otherwise, there will be no such problem. I need your favor again. Thanks in advance.

How could I display Table B from Table A?

I was able to merge columns POINT and PERCENT using CalculatedColumn. However, when I rearrange the columns and sum it at the footer, it will result in an error and only display sum for POINT, not sum for both POINT and PERCENT. Can you show me how this could be done?

Thanks.

KoolReport commented on Jul 31, 2017

As I see in the table B, seems you merge the header of Point and Percent into M Point. The Table widget does not support it. You only can show below result with Table widgets.

NamePointPercent
x1050.0%
y1050.0%
Total20100.0%

Below code to generate table like above:

Table::create(array(
    ...
    "showFooter"=>"bottom",
    "columns"=>array(
        "name",
        "point"=>array(
            "footer"=>"sum",
        ),
        "percent"=>array(
            "footer"=>"sum"
            "type"=>"number",
            "suffix"=>"%"
        ),
    )
));
zenon commented on Jul 31, 2017

Oh I see. Thanks.

Referring to your guidance above, I realized that "2017-07-01" is from the user's input. The date changes according to user's input.

->pipe(new ColumnMeta(array(
    'date("2017-07-01")'=>array(
        "name"=>"date_form", //Rename the column name
    )
)))

How could the above be done based on the user's input, as the column name changes according to the user's input? Example: When the user selects 2017-07-01, the column name will be date("2017-07-01"). And when the user selects 2017-07-19, the column name will be date("2017-07-19").

Thanks.

KoolReport commented on Aug 1, 2017

I am afraid that is too difficult, the ColumnMeta and other process expected the column name should be static. One question: Why you could not change SQL?

KoolReport commented on Aug 1, 2017

One more questions: How to you get the user input?

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None