Query-based tab?
Archived from the Xataface Users forum.
gorzek — Mon Jul 14, 2008 8:27 am
Sorry for bombarding the board with questions… hopefully I will have fewer of them as I dig deeper into Xataface.
I want to have a top-level tab (on the same level as all tables) that is based on the results of a query but displays just like any other tab. Basically, it will display values from another table, but constrained by a query.
I can run the query I want in the delegate class just fine, and parse the results there, but I really just want it to use the standard list/view algorithms based on the results of my query. Is there, for instance, a function I can pass each row to that will render it correctly? (RenderRow doesn’t seem to work for this, as-is.)
shannah — Mon Jul 14, 2008 11:07 am
If you are using mysql 5, the easiest way to do this is with a view (as you can use views almost like normal tables).
If you don’t have this luxury, the easiest way is probably just to create a link using the xataface url conventions with the query that you like. You can then add this link to the table tabs at the top quite easily (see http://xataface.com/forum/viewtopic.php?t=4537 ) for information on appending arbitrary links to the tables menus.
-Steve
gorzek — Mon Jul 14, 2008 12:58 pm
I thought about using a view. I suppose I could do that, but I would still need to filter it down–I wouldn’t want a separate table for every user.
The link you provided looks promising, in any case. A custom action may be the way to go, here. Thanks!
shannah — Mon Jul 14, 2008 1:09 pm
Hi Gorzek,
If it is the case that you want to filter the results of a table for different users, you can do this is multiple ways.
-
If you want to prevent the user from seeing certain records, you can use security filters. (http://xataface.com/documentation/how-t … ty_filters)
-
If you don’t necessarily want to prevent the user from seeing certain records but you want to filter the records for the user’s convenience, you can either provide the user with a link directly to the table with appropriate queries in place (e.g. index.php?-table=foo&-action=list&ownerID=10 for all foo records with ownerID = 10) (as described in my previous post), or you can add a snippet of PHP to the beginning of your index.php file to add the appropriate query parameters.
-Steve
gorzek — Mon Jul 14, 2008 1:38 pm
Putting it right in the query is exactly what I was thinking of! I knew I had done it somehow before, and that’s exactly what it was. It was something I wrote a couple years ago, and for the life of me, I couldn’t remember how I did it. Making a tab that filters just by the user is exactly what I want. I will give this a shot, but I think that is just what I was looking for! Thanks!
gorzek — Thu Jul 24, 2008 1:22 pm
I noticed that putting a field value in the URL does not seem to work for calculated fields. Is there a way around that? I actually want to filter the list view based on the value of a calculated field.
I did use a MySQL view for a while, but it ended up being a lot of maintenance, because all I really wanted was a filtered view for user convenience, but did not want to constrain their actions–I still wanted them to be able to add records to the real table behind the view, etc. It ended up being a significant hassle and I tried to go back to a single table and no view.
What I am trying to do is have a table of projects, and another table listing the project’s users. A tab called “My Projects” is meant to display all the projects to which you belong. I created a calc field called “isuser” for that purpose, which joins the tables and determines if the current user is on that project. However, I cannot filter by adding “&isuser=1” to the URL. It just doesn’t do anything–it displays all records, regardless. If I could use that calc field to filter, that would really be ideal.
I didn’t like using a view because, as I said, it tried to perform all actions on the view (which is not allowed for anything that changes data, of course), when I really just wanted it to fall back to the real projects table.
Do you have any ideas here?
gorzek — Thu Jul 24, 2008 2:35 pm
I figured it out. I kept getting errors when doing a LEFT JOIN between the tables. It turned out it was because I was specifying a “timestamp” field. I guess MySQL doesn’t cotton to that.
In any case, I extracted one field from the join, and am using that to filter. I don’t need to display it–it’s nothing more than a field to indicate what users should see a given project, if specified in the URL.
Thanks again!
andperry — Sun Mar 01, 2009 6:57 am
I’ve found a need to do the same sort of thing. I’m new to MySQL views - learned about them via this thread, so decided to try it out. Created some views and they seem to be OK - the records all display correctly using phpMyAdmin.
Tried adding the views to the Xataface application by adding their names/descriptions to the table list in conf.ini. At this stage I have not created any configuration files for the individual views. When clicking the tab for one of the views, get a server error to say that the page cannot be displayed.
Any ideas what might be going wrong? Am I missing something?
Thanks,
Andrew.
shannah — Sun Mar 01, 2009 9:19 am
When using views in Xataface you have to specify the primary key in the fields.ini file for the view.
e.g.
- Code: Select all
[person_id] Key=PRI
Capitals matter here.
If that doesn’t get you going, check your error log.