KoolReport's Forum

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

Group text issue on Table #1228

Closed Peter Harari opened this topic on on Dec 26, 2019 - 7 comments

Peter Harari commented on Dec 26, 2019

Hello.

I added grouping to a Table report of mine but I'm having an issue with the top property's text. I defined it like:

'code_product_name' => array(
    'group' => array(
         "top" => "<b>{code_product_name} - {code_product}</b>"
    )
)

code_product_name is being replaced by it's related content, but code_product is not. Eg:

Below there is a dump of the whole report settings, and you can see that code_product is found on each row in data array.

My question is: Is that a limitation or am I doing it wrong?

Thank in adv

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [code] => 001
                    [code_product_name] => Ancoras
                    [name] => Subtipo 1.2
                    [code_product] => 005
                )

            [1] => Array
                (
                    [code] => 0005
                    [code_product_name] => Instrumentais
                    [name] => teste error 1
                    [code_product] => 004
                )

            [2] => Array
                (
                    [code] => 002
                    [code_product_name] => Instrumentais
                    [name] => Teste produto Ancoras - Placas
                    [code_product] => 004
                )

            [3] => Array
                (
                    [code] => 0003
                    [code_product_name] => Parafusos
                    [name] => Teste código 1
                    [code_product] => 001
                )

            [4] => Array
                (
                    [code] => 0004
                    [code_product_name] => Parafusos
                    [name] => Teste novo 1
                    [code_product] => 001
                )
        )

    [columns] => Array
        (
            [code] => Array
                (
                    [label] => Código
                    [field] => code
                    [template] => 
                    [cssStyle] => Array
                        (
                            [th] => text-align: center; width: 200px; text-align: center
                            [td] => width: 200px; text-align: center
                        )
                )

            [code_product_name] => Array
                (
                    [label] => Tipo de Produto
                    [field] => code_product_name
                    [template] => 
                    [cssStyle] => Array
                        (
                            [th] => width: 400px;
                            [td] => width: 400px;
                        )
                )

            [name] => Array
                (
                    [label] => Subtipo
                    [field] => name
                    [template] => 
                    [cssStyle] => Array
                        (
                            [th] => 
                            [td] => 
                        )
                )

            [code_product] => Array
                (
                    [label] => 
                    [field] => code_product
                    [template] => 
                    [cssStyle] => Array
                        (
                            [th] => 
                            [td] => 
                        )
                )
        )

    [excludedColumns] => Array
        (
            [0] => code_product_name
            [1] => code_product
        )

    [grouping] => Array
        (
            [code_product_name] => Array
                (
                    [top] => <b>{code_product_name} - {code_product}</b>
                )
        )
)
David Winterburn commented on Dec 27, 2019

Hi Peter,

Please try removing "code_product" from excludedColumns and see how it goes. Thanks!

Peter Harari commented on Dec 27, 2019

Hi David, merry christmas(kinda late).

I need to use code_product value but I can't show it in the table. Removing it from excludedColumns makes it be displayed.

There is another way to hide it without excludedColumns?

Thanks!

David Winterburn commented on Dec 31, 2019

Hi Peter,

That's good to know we are in the right direction to solve this problem. I will ask the dev team of the Table widget if there's a good way to exclude a column while still using it in grouping.

However, in the mean time you could try this workaround by adding a CSS class to code_product column and header and then hide them by CSS like this:

<style<
    .code-product {
        display: none;
    }
</style>
<?php
    Table::create(array(
        "cssClass" => array(
            "th" => function($colKey) {
                if ($colKey === 'code_product') return 'code-product';
                else return '';
            },
            "td" => function($row, $colKey) {
                if ($colKey === 'code_product') return 'code-product';
                else return '';
            }
        ),
    ));

Let me know how this works for you. Thanks!

Peter Harari commented on Jan 7, 2020

Hi David.

I'm sry for the late answer, got some priorities ahead of this.

Well, I dind't works for me. I tried with cssStyle instead of cssClass, there is any problem with it? I believe its the same outcome after all: display: none directly on style tag on th and td.

In fact it hide the column, but the value didn't appeared in the other column. Check you this screenshot:

The data used to create the table is the following:


{
	"data": [{
		"code": "001",
		"code_product_name": "Ancoras",
		"name": "Subtipo 1.2",
		"code_product": "005"
	}, {
		"code": "0005",
		"code_product_name": "Instrumentais",
		"name": "teste error 1",
		"code_product": "004"
	}, {
		"code": "002",
		"code_product_name": "Instrumentais",
		"name": "Teste produto Ancoras - Placas",
		"code_product": "004"
	}, {
		"code": "0003",
		"code_product_name": "Parafusos",
		"name": "Teste c\u00f3digo 1",
		"code_product": "001"
	}, {
		"code": "0004",
		"code_product_name": "Parafusos",
		"name": "Teste novo 1",
		"code_product": "001"
	}, {
		"code": "0006",
		"code_product_name": "Parafusos",
		"name": "Teste sequecence 1",
		"code_product": "001"
	}],
	"columns": {
		"code": {
			"label": "C\u00f3digo",
			"field": "code",
			"template": null,
			"cssStyle": {
				"th": "text-align: center; width: 200px; text-align: center",
				"td": "width: 200px; text-align: center"
			}
		},
		"code_product_name": {
			"label": "Tipo de Produto",
			"field": "code_product_name",
			"template": null,
			"cssStyle": {
				"th": "width: 400px;display: none",
				"td": "width: 400px;display: none"
			}
		},
		"name": {
			"label": "Subtipo",
			"field": "name",
			"template": null,
			"cssStyle": {
				"th": "",
				"td": ""
			}
		},
		"code_product": {
			"label": "",
			"field": "code_product",
			"template": null,
			"cssStyle": {
				"th": "display: none",
				"td": "display: none"
			}
		}
	},
	"excludedColumns": [],
	"grouping": {
		"code_product_name": {
			"top": "<b>{code_product_name} - {code_product}<\/b>"
		}
	}
}

Did it made any mistake about the approach you have proposed?

Thank you.

David Winterburn commented on Jan 8, 2020

Hmm, it's a bit strange. If you remove the rule "display: none" for column code_product does the groups work fine?

KoolReport commented on Jan 8, 2020

@Peter: Keep the cssStyle as you did and do the following:

	"grouping"=>array(
		"code_product_name"=>array(
                        "calculate"=>array(
                            "{code_product}"=>array("max","code_product")
                        )
			"top"=> "<b>{code_product_name} - {code_product}<\/b>"
		)
	)

Reason: The row is grouped by {code_product_name} so it is available in the header, the code_product is not aggregated so it is not available. So above way will provide the "{code_product}" value, we know that all the rows with same code_product_name will have the same code_product so basically max operation will provide the way to access the code_product value. FYI, min operation will also work.

Peter Harari commented on Jan 8, 2020

Hi!

It works! Thank you so much.

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
solved

None