marmelab / ng-admin

Add an AngularJS admin GUI to any RESTful API
http://ng-admin-book.marmelab.com/
MIT License
3.95k stars 728 forks source link

Add filter to reference depending on another reference #810

Open maximk-1 opened 8 years ago

maximk-1 commented 8 years ago

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?

fzaninotto commented 8 years ago

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!

hauptbenutzer commented 8 years ago

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.

maximk-1 commented 8 years ago

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

Have no such experience to code it =(

sam2x commented 8 years ago

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 ?).

tdeheurles commented 8 years ago

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 ...

windmaomao commented 8 years ago

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

    .filters(function(entry) { 
        return { 'projectId': entry.project.id };
    } 
mradosta commented 8 years ago

+1

hobywhan commented 8 years ago

+1

faboulaws commented 8 years ago

+1

allentc commented 8 years ago

+1

fatkhanfauzi commented 7 years ago

+1

chenyaoyi110 commented 6 years ago

+1

Zuhayer commented 6 years ago

= +6

BoussonNicolas commented 6 years ago

+1

Kmaschta commented 6 years ago

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!

BoussonNicolas commented 6 years ago

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

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!! :)

Zuhayer commented 6 years ago

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