Problem Controlling Column Display in Table View

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
gmusgrave
Posts: 25
Joined: 2013-08-15 17:27
Location: Mexico

Problem Controlling Column Display in Table View

Post by gmusgrave » 2013-10-03 13:33

I want to show a limited set of columns in Table View when a user is logged in as a guest.

I added the following to the TABLENAME_init() function in the hook file for this table:

Code: Select all

// Customise views and features for public users
		if ($memberInfo['group'] == 'anonymous') {
			// Prevent them from using the "Save as CSV" function
			$options->AllowCSV = 0;
			
			// Select the columns they can see in the Table View
			// Numbered from 1 = 'ID' to 11 = 'Notes'
			$options->ColNumber = array(3, 5, 6, 7, 8);		
		} 

If I understood the documentation for the Datalist object, the columns displayed in Table View are controlled by the ColNumber array. Indeed, TABLENAME_view.php initialises $x->ColNumber to an array of the normal columns I selected as visible in AppGini.

I know that the guest is indeed "anonymous" because I displayed the contents of $memberInfo['group'] in a debug statement. Further, the AllowCSV option in the same "if" condition of my code works perfectly.

I've also displayed the contents of $options->ColNumber in a debug statement (using print_r), and they have been changed as per my code.

Further, I added a debug statement to TABLENAME_view.php after returning from calling TABLENAME_init(), but before rendering the page. Here also $x->ColNumber has been changed by my code.

In spite of all this, all columns that were initially set in TABLENAME_view.php before calling the TABLENAME_init() function are still being displayed. One odd thing is that the last five columns have a yellow down-arrow graphic showing at the top of the column as if they had been sorted as descending, although no such sort has been applied.

Am I missing something fundamental here, or is this a bug?

Any help would be greatly appreciated. Thanks,
Garry

gmusgrave
Posts: 25
Joined: 2013-08-15 17:27
Location: Mexico

Re: Problem Controlling Column Display in Table View

Post by gmusgrave » 2013-10-10 18:10

UPDATE:

My code is working perfectly, and I don't think there's a bug in the AppGini code. So why doesn't it work?

I believe the problem is with the documentation. A quick inspection of the AppGini code shows that ColNumber doesn't really seem to control which columns are displayed in table view, contrary to what it says in the documentation. The only thing that seems to affect this is the TABLENAME_templateTV.html file in the templates directory.

This template file is generated by AppGini when you compile the app.

When I have a bit more time, I'm going to look into changing this file on-the-fly based on user permissions just before generating the table view. If I succeed, I'll post the code on the forum.

Garry

adz1111
Posts: 12
Joined: 2014-03-31 12:24

Re: Problem Controlling Column Display in Table View

Post by adz1111 » 2014-04-06 08:51

Hi

Did you ever solve this as I too wish to limit columns being displayed in TV (and DV) based on the user name.

Thanks

shkdxb
Veteran Member
Posts: 40
Joined: 2013-06-28 18:18

Re: Problem Controlling Column Display in Table View

Post by shkdxb » 2016-03-07 04:11

I could able to hide the content by using below code in Table view.
This code is inserted inside tablename_init(){ } in hooks/tablename.php file

Code: Select all

	function tablename_init(&$options, $memberInfo, &$args){
		$oldArray=$options->QueryFieldsTV;
		$options->QueryFieldsTV='';
		foreach($oldArray as $field => $caption){
			if($field=='`tablename`.`field1`'){
				$options->QueryFieldsTV[$field]="";// field1 will be blanked
			}else if($field=='`tablename`.`field2`'){
				$options->QueryFieldsTV[$field]="";// field2 will be blanked				
			}else{
				$options->QueryFieldsTV[$field]=$caption;
			}
		}
		}
but cannot hide the column entirely. Tried $options->ColNumber but no success.

Post Reply