display data to the table depending on the user

display data to the table depending on the user

majkellvzmajkellvz Posts: 8Questions: 3Answers: 0
edited March 2019 in Free community support

I need to show only the properties the active user has registered to be sold.

$table = $this->createDataTable()
            ->add('name', TextColumn::class, [
                'searchable' => true,
                'globalSearchable' => true,
                'label' => 'Name'
            ])
            ->add('contact', TextColumn::class, [
                'searchable' => true,
                'label' => 'Contact',
                'field' => 'contact.name'
            ])

            ->add('user', TextColumn::class, [
                'searchable' => true,
                'label' => 'Agent',
                'field' => 'user.username'
            ])
            ->add('id', TextColumn::class, [
                'searchable' => false,
                'label' => ' '
            ])
            ->add('issold', TextColumn::class, [
                'searchable' => false,
                'label' => 'Sold/Un-Sold'
            ])
            ->createAdapter(ORMAdapter::class, [
                'entity' => Property::class,
            ])
            ->handleRequest($request);

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    I'm not sure what API you are using there (it isn't one of ours), but I'd suggest breaking the chain and adding if statements:

    $table = $this->createDataTable();
    
    if ( userHasNamePermissions )
                $table->add('name', TextColumn::class, [
                    'searchable' => true,
                    'globalSearchable' => true,
                    'label' => 'Name'
                ]);
    }
    
    // etc
    

    Allan

  • majkellvzmajkellvz Posts: 8Questions: 3Answers: 0

    https://omines.github.io/datatables-bundle/ this is the guide I am using.

    $table->createAdapter(ORMAdapter::class, [
    'entity' => Property::class,
    'criteria' => [
    function (QueryBuilder $builder, $user) {
    $builder->andWhere($builder->expr()->like('p.user', ':user'))->setParameter('user', $user);
    },
    new SearchCriteriaProvider(),
    ],
    ]);

    this is the code I came up and still not working

This discussion has been closed.