Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right way to integrate extra columns into grid? #58

Closed
print opened this issue Nov 29, 2011 · 3 comments
Closed

Right way to integrate extra columns into grid? #58

print opened this issue Nov 29, 2011 · 3 comments

Comments

@print
Copy link

print commented Nov 29, 2011

Hi,

i search for the right way to bring in some extra columns into my grid.

My first example is a simple image column, like "src/folder/{{ row.id }}.jpg".
I am not sure what's the right way for this, i hope anyone can get me a short tipp?

My second problem are columns with a ManyToOne situation:

 * @GRID\Source(columns="id, name, category")
 */
class MyClass
{
....
     * @GRID\Column(id="category.name", title="category", field="category")
     */
    protected $category;

But my column category does not work/display in my grid with this configuration.

I hope anyone can help?

Thanks!

@ghost
Copy link

ghost commented Nov 29, 2011

  1. create own class like
use Sorien\DataGridBundle\Grid\Column\Column;

class ImageColumn extends Column
{

public function getFilters()
{
    return array();
}

public function renderCell($value, $row, $router)
{
    return '<div class="image" style="background-image: url(\''.Image::getPath().'/'.$value.'\');"/></div>';
}

public function getType()
{
    return 'image'; //important
}
}

add to DI

    <service id="grid.column.image" class="PathToClass\ImageColumn" public="false">
        <tag name="grid.column.extension" />
    </service>

and use it like this

 * @ORM\OneToOne(targetEntity="Image", cascade={"persist", "remove"})
 * @ORM\JoinColumn(name="main_image_id", referencedColumnName="id")
 * @GRID\Column(type="image", field="mainImage.file", size="64") //set type image
 */
private $mainImage;

dont use id for property mapping

@GRID\Column(title="category", field="category.name")

@Abhoryo
Copy link
Member

Abhoryo commented Nov 29, 2011

Without create a class, maybe you can add a simple column and fill it in the template. What do you think @S0RIEN ?

@ghost
Copy link

ghost commented Nov 29, 2011

yes, its easier way, when you don't need to store same special data, or create own filterings

@ghost ghost closed this as completed Nov 29, 2011
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants