ng-admin icon indicating copy to clipboard operation
ng-admin copied to clipboard

Add filter to reference depending on another reference

Open maximk-1 opened this issue 9 years ago • 17 comments

Hi.

i have 2 reference fields, for example, permissions and users, and i want to filter users filed depending on permissions choice, something like:

myEntity.creationView()
    .fields([
        nga.field('permission_id', 'reference')
            .targetEntity(permissions)
            .targetField(nga.field('name')),
        nga.field('user_id', 'reference')
            .targetEntity(users)
            .remoteComplete(true)
            .targetField(nga.field('name'))
            .permanentFilters({ 'permission_id': entry.values.permission_id })
            .template('<ma-reference-field ng-if="entry.values.permission_id" field="::field" value="value" datastore="::datastore"></ma-reference-field>')
    ]);

Is it possible?

maximk-1 avatar Nov 23 '15 14:11 maximk-1

nope, for that permanentFilters() should accept a function. But it's a great feature idea, I suggest you give it a try and send us a PR!

fzaninotto avatar Nov 26 '15 21:11 fzaninotto

Seems like this was possible before? Still, even if one was able to reduce the dataset by means of a callback, this would only work as long as the chosen field (in this example permission_id) is not changed. I would be willing to implement this feature but I'm not really sure how to go about the synchronization aspect.

hauptbenutzer avatar Dec 03 '15 01:12 hauptbenutzer

I suggest you give it a try and send us a PR!

Have no such experience to code it =(

maximk-1 avatar Dec 08 '15 12:12 maximk-1

Hey, i got the exact same situation, i wanted to restrict stores based on the current location of my entry. It would be awesome to let permanentFilters having access to the current entry value (callback with entry argument ?).

sam2x avatar Feb 06 '16 10:02 sam2x

Hey, I confirm, there are lots of situation where it could be really good :D No experience with Angular too :/ will have a look if I can do something ...

tdeheurles avatar Mar 01 '16 15:03 tdeheurles

+1 for this feature. maybe we shouldn't reuse the name "permanentFilters", maybe a new call

    .filters(function(entry) { 
        return { 'projectId': entry.project.id };
    } 

windmaomao avatar Apr 27 '16 22:04 windmaomao

+1

mradosta avatar May 02 '16 11:05 mradosta

+1

hobywhan avatar May 16 '16 14:05 hobywhan

+1

faboulaws avatar Jun 01 '16 07:06 faboulaws

+1

allentc avatar Aug 05 '16 21:08 allentc

+1

fatkhanfauzi avatar Aug 29 '17 07:08 fatkhanfauzi

+1

chenyaoyi110 avatar Oct 26 '17 12:10 chenyaoyi110

= +6

Zuhayer avatar Nov 02 '17 05:11 Zuhayer

+1

BoussonNicolas avatar Feb 05 '18 14:02 BoussonNicolas

Sorry guys, but as we said in our last blog post about ng-admin, we're focusing our efforts on admin-on-rest and no longer on ng-admin.

I see that this specific issue is popular, but it isn't a security issue nor a bug so we won't invest for it for now. I can only suggest to make your own PR for it!

Kmaschta avatar Feb 05 '18 16:02 Kmaschta

I just made it work perfectly combining the codes from various topics:

  • https://github.com/marmelab/admin-config/pull/64/files
  • https://github.com/marmelab/ng-admin/pull/938/commits/eac1a6fd0d5ae78174f08a56506e99aa695906ec (thanks a lot Vasia Korobkin !)

and adding "scope.refresh('');" to this piece of code: if (!!field._getPermanentFilters) { scope.$watch('entry.values', function(newValue, oldValue){ field._getPermanentFilters(newValue); scope.refresh(''); }, true); } This is indeed an extra useful feature!! :)

BoussonNicolas avatar Feb 05 '18 16:02 BoussonNicolas

I also made it work. @JasnahKolhn's advice helped alot.

Zuhayer avatar Feb 07 '18 15:02 Zuhayer