Default Table Filtering

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Default Table Filtering

Post by kbarrett » 2019-03-19 20:00

Hello,

I am trying to create a default view on a table based on the logged in user. I have users sorted by employee, department and position (using the Custom2 value in the Admin section). I have created groups in the Admin area based on departments (HR, Executive, Finance, etc) that narrows it down a bit. I have tried several unsuccessful times to add a default filter using this info, https://bigprof.com/appgini/tips-and-tu ... ult-filter to no avail. I would like to be able to filter the table view one step further beyond the user's department (Group) by their position. Am I headed down the right road? If, so, can someone point me the rest of the way and if I am totally lost, redirection?
TIA
Kevin

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Default Table Filtering

Post by kbarrett » 2019-03-20 19:01

So far I have tried many different iterations and combinations of the following:

function MyTable_init(&$options, $memberInfo, &$args){

if(!$_POST['FilterField'][1] && !$_GET['FilterField'][1]){
$memberInfo = getMemberInfo();
addFilter( 1, 'and', 2, '==', $memberInfo['custom']['2']);
}
return TRUE;
}

Basically I want the table records only viewable by a certain department position. I have created a group permission for the department, that works but I want to narrow it by position. The filed 1 is the department(e.g. Facilities) and field 2 is the position (e.g. Carpenter) the memberinfo custom 2 is also position in the membership_users table. Am I way off base here?

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Default Table Filtering

Post by pbottcher » 2019-03-20 20:53

Hi can you try

addFilter( 1, 'and', 2, 'equal-to', $memberInfo['custom'][2]);
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Default Table Filtering

Post by kbarrett » 2019-03-20 21:09

Hi!

Thank you for the reply and the assistance! I tried changing the line to what you suggested. Unfortunately I still see all the records for the department it does not filter out the positions.

Maybe I should include the Department field gets populated automatically by the value <%%creatorGroup%%>. I am also using the latest version of AppGini.

Further to this on the same table to prevent users inadvertently editing fields they shouldn't I am trying to add this to populate the fields in the detail view when adding new records.

function MyTable_before_insert(&$data, $memberInfo, &$args){


$memberInfo = getMemberInfo();
$data['Position'] = $memberInfo['custom'][1];
$data['Created_By'] = $memberInfo['MemberID'];

return TRUE;
}

I can't get that to work either.

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Default Table Filtering

Post by kbarrett » 2019-03-21 20:43

Hmmm, it must be a complicated problem. 48 views and no solutions yet. I am still playing with different permutations and if I come up with something I will post it. I would rather not have to create a myriad of different groups in the Admin section that is just asking for trouble.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Default Table Filtering

Post by pbottcher » 2019-03-21 22:41

Hi,

to correct the answer, if you use the custom2 field in the membership_user table you need

addFilter( 1, 'and', 2, 'equal-to', $memberInfo['custom'][1]);

where 2 is the second field of you table.

What are you trying to acheive within the DV? In what you posted above, you will overwrite the "Position" with the value of the custom2 field and the "Created_By" with the memberID. This happens when you save the record.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Default Table Filtering

Post by kbarrett » 2019-03-22 15:21

Hi again,
Thanks for replying!

Unfortunately, addFilter( 1, 'and', 2, 'equal-to', $memberInfo['custom'][1]); doesn't work on filtering the table view. I discovered my error just before I read your message last night and tried it. :( .

Also thanks for pointing out the part about overwriting, I had originally thought that having the field auto-fill might reduce user input errors when editing the original post. However, if I leave the "Created By" field as is with a look up to the employee and leave the position as is and just add an edited by field it might solve the problem.
I do wish I could filter the table view in a more granular fashion though

kbarrett
Veteran Member
Posts: 50
Joined: 2019-02-24 16:35
Location: Calgary Alberta

Re: Default Table Filtering

Post by kbarrett » 2019-03-25 19:57

Hey PBottcher

Thanks for your help with this one too. Colour (guess the spelling shows I am Canadian) me dim, I played around with the filter numbers and finally got it to work.

Cheers,

Post Reply