Datatables editor and Views
Datatables editor and Views

I am asking the question, although I have the feeling that I already know the answer:
Can I use database views (relational views) instead of just tables?
My guess is that the first hurtle is that views have no indexes and datatables, seems to me, needs the indexes.
Did anybody tried this before?
Answers
Sort of. You can use the VIEW for the getting of data, but you need to write back to an actual table - there is an example of that here.
The lack of index isn't an issue, but you do need to be able to uniquely identify a row (normally a primary key index, but it could be something else).
Allan
Bearing that in mind, here is an example using a view. I need to Mjoin a table with itself. For that you need a view. The table I use is called "contract" and the view on "contract" is called "underlying". The link table between the two which is called "derivative_has_underlying" must be a real table, not a view.
Allan, the example that you shared is great.
Shame on me because I saw it before but I did not pay enough attention to the details. So 'staff_newyork' is the view where you read and 'users' is the table where you write.
I will give it a shot and report back here.
Now, in this example, you never state what the unique identifier is. I assume you can always use
Yes. I think you'll need to make sure the name is the name for the primary key column and that matching value in the VIEW.
Allan
It took me a long time, but I figured out what the problem was:
Create and Edit use a sql query that includes RETURNING.
Oracle does not support insert statements with RETURNING clauses in views. That is where the problems is.
That is correct. As I mentioned in my first reply:
The example I linked to does that by specifying the VIEW for the
readTable
and the underlying table that is to be written to is the table specified in the constructor.Allan
The problem is that those views are build with some GIS libraries from a GIS software product that strongly advices you against writing data to the tables. They insist that you write to the views.
Anyways, I found a work around (more like a hack) to post to the views with some custom code, and still get to use the good looking datatables, that are used across our website in different ways.
Awesome - good to hear you've got a workaround.
Allan