Deny all fields except for a few
Hi all,
is there a way to allow only a few specific fields and deny all others?
Background: I have a layer with 30+ fields. I only want the users to see a few of them (let's say 5). Using the UI, I'd have to set a Deny permission for each of the 25+ denied fields. Using Advanced Permissions doesn't really help because even there, I will have to write a denyField()for each field.
Is there a way to do this? What I need would be something like a wildcard, or a denyAllFields() method. The only way I found was to iterate over the fields, like this:
layer.fields.forEach(function (item) {
denyField(item.name);
});But this throws a lot of Varint overflow errors, and I believe there should be a better way to do this.
-
Hi Marius,
This works for us to allow only a few specific fields and denying all others:
const allowedSet = new Set(['type', 'survstatus']); // Deny all fields layer.fields.forEach((f) => { const fname = f && f.name; try { denyField(fname); } catch (e) { // Field might not exist on this layer? } }); // Explicitly allow whitelisted fields allowedSet.forEach((fieldName) => { try { allowField(fieldName); } catch (e) { // Field might not exist on this layer? } });By the way, if you use denyfield do you find you can no longer sort any other fields ?
1 -
Thank you for your replay. Your code works, but I still get the Varint errors.
And yes, I also get the sorting bug.
0
Vous devez vous connecter pour laisser un commentaire.
Commentaires
2 commentaires