How to setup a Select Filter
How to setup a Select Filter
Mike Storey
Posts: 25Questions: 7Answers: 0
Pardon the new-b question, I'm still pretty new to jQuery. I'd like to setup a selectmenu, populated by a json query, and on change in that control, repopulate the table editor using the selected value as a parameter in the post call. I'm guessing it's pretty easy. A pointer to a sample would be greatly appreciated, as I'm still at the copy/paste level of competency with several of these technologies.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I think you might need to elaborate a little bit more on what you are looking for please.
You can use the
field().node()
method to get the container node for a field and then use a bit of jQuery to attach an event listener to trigger an action on change. For example:Assuming I've understood correctly.
A new
dependent
method will be available in Editor 1.4 (in the next beta) which will make this much easier.Allan
I think I'm getting closer to my desired outcomes.... but still struggling with what I suspect are very simple items. Here is a more complete description of what I'm trying to accomplish. I have a javascript variable customerID, that I want to pass to the server side PHP code, and have that code use the value in a where clause on the generated select statement. I suspect I will need something like the following....
And in then in table.staff.php
But alas, no "getQuery" that I can find.... I may be going about it all wrong, but my objective is to filter the data based on the contents of a javascript variable, and instigate a "refresh" after changing the value. I want the total row count to reflect the filter, so customer X my have 20 rows, and customer Y may have 15 rows. I want the table count in the footer to reflect this as well. It's a kind of "pre" filter of data before it goes into the DataTable, as opposed to fetching all the data and then "searching" it in the Data Table.
I see - so you want to reduce the data shown in the DataTable by the where condition.
The way to do that is to send the additional data to the server-side script using the
ajax.data
option. For example:Then you can use
ajax.reload()
if you want to change the customer id (thenewId
variable in this case - you could read from a select list or whatever to get the value).Then in your server-side script for Editor you can use the
where()
method to add the required condition - for example:That will do the "pre-filter" your want.
Allan
Thanks!
Ok, so the table is now populating as I wanted, but the bubble form is now reporting an Editor System Error on update. The data in the database IS updated, but not in the web page. Simple testing point's to the ->where() statement in table.replace.php (If I remove it the error goes away along with the filter). The Safari console shows the ajax request/response and it all looks good with a return status of 200. I can see the request payload, but either Safari doesn't show the reply content or I can't figure out where to look. I'll paste what I think is the relevant code below. I will get the application installed at OpenShift but that may be a few days so please don't wait if you have ideas on what the problem is.
table.customer.js
table.replace.js
table.replace.php
The error that you are seeing is presumably related to the fact that
$_POST['customerId']
is not defined when Editor makes its Ajax submission?If so, then you need to submit that data using
ajax.data
in exactly the same way that you've used DataTables' ownajax.data
option - i.e. you need to send the additional information required.Allan
Looking at the request/reply in the Safari debugger I can see that the customerID is in the request, however it has a value of 0, and the datatable-ajax-post-data callback function in table.replace.js is not called prior to the update being sent to the server. Since this is only on the calls from the editor bubble, I'm not sure how I can change what is submitted when "update" is clicked, or why that callback function is not called before the update. If you can provide me with a little more direction on how to override the ajax call being used by the bubble editor that would be great.
Could you show me the code you are using please? The
ajax.data
callback should be getting called every time Editor makes an Ajax request.Allan
I tried to put all the relevant code above, so I'll put the full content here. The only code in the html file is "var theCustomer = 0;" and the includes for table.replace.js and table.customer.js.
Here is the code for table.customer.js (the only relevant code here is the "setCustomer" function which set's the value of theCustomer.
Here is table.replace.js, with the data: callback function. To test if this function was being called I simply put an alert(theCustomer); call into the function. (that statement has been removed from the code below)
and finally, here is table.replace.php - if I comment out the ->where line, the updates work without errors.
In your Editor initialisation. That doesn't appear to be using the
ajax.data
option I mentioned. The DataTables part is using it in theajax
object - I would suggest you basically want what you have in the DataTables part in the Editor part as well - unless I'm missing something?Allan
Duoh..... Thanks, sometimes you just need a second set of eyes (and some experience doesn't hurt)