Filtering data being shown from MySQL table

Filtering data being shown from MySQL table

jdmorsejdmorse Posts: 8Questions: 1Answers: 1

Using wordpress as my CMS and have integrated DT and DT editor. Trying to get permissions setup.

I have a set of data that is loaded nightly and has the user's first and last name in a column. Wordpress is connected to our active directory and has the information on all active users. Doing this creates a user in wordpress with their first and last name. I can call on current user details within wordpress and I am trying to filter data displayed in DT by their name.

I seem to be having trouble implementing this: https://editor.datatables.net/manual/php/conditions#

This question has an accepted answers - jump to answer

Answers

  • jdmorsejdmorse Posts: 8Questions: 1Answers: 1
    edited May 2015

    My question may have not really been a question.

    Where and how do I implement that. That page gives small snippets of code, but when I add what I think it correct to my php file being used by AJAX I get nothing in return. It is like the filter is being applied, but not correct. Just shows 'Loading...'

    What I need is a way to implement the where function while using datatables editor.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    Could you show me the PHP you are using please? It should be a case of adding the where() method to the Editor instance chain (before the process() method is called of course!).

    Also, it might be worth checking your server's error logs - it sounds like there might be an error occurring, which would hopefully be logged there.

    Thanks,
    Allan

  • jdmorsejdmorse Posts: 8Questions: 1Answers: 1

    Allan,

    Thanks for the post. I appreciate the help. Spent too much time trying to deal with work distractions than focusing on what I was doing. I haven't narrow down the cause, but wordPress does not like DataTables AJAX it seems. To get around this I have all of the DataTables as well as the Editor sitting outside WordPress and then just calling it onto a page. When I try to run the files (JS/PHP) within wordpress is when I have some issues.

    Since I am running the DataTables AJAX calls outside WordPress it would only make sense that DataTables cannot see my WordPress data.

    I am pretty sure that is the cause of my problem. I was just lacking focus. Sometimes I have to get away from distractions so I can think clearly.

    Thanks for your input. I will report back either way. Working or not.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    :-). No problem. Give me a shout if there is anything you would like to bounce off me.

    Allan

  • jdmorsejdmorse Posts: 8Questions: 1Answers: 1

    Allan,

    If I am setting a variable on the page in php and just using in the php editor why would I just get a message in the datatable saying "Loading"

    Example line:
    Editor::inst( $db, 'log', 'id' )->where( 'Driver', $user )

    If I use something like:
    Editor::inst( $db, 'log', 'id' )->where( 'Driver', 'Test User' )
    It will correctly filter results being displayed.

    What do I need to do to be able to filter using a variable?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Sounds like you might be getting an invalid JSON response from the server - probably there is an error message embedded in the response. You can you your browser's developer tools to see what that might be.

    The most obviously thing to me would be if $users is undefined. Where does it come from?

    Allan

  • jdmorsejdmorse Posts: 8Questions: 1Answers: 1
    edited May 2015

    Allan,

    I am not getting any response it seems. I am setting the value of $user on the page that contains the table and is making the calls. I have tried defining $user in the same PHP file that the datatables JS is calling. Same result. Just "Loading...". I have included a screenshot of the page as well as the console errors. The only error is just because there is nothing to apply options to.

    http://i.imgur.com/79Orz45.png

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    That error suggests to me that their is a field with an options() method being called which does not have a corresponding field on the client-side defined. Check the name of the fields in the PHP which have options() methods and compare to the client-side Editor initialisation.

    Allan

  • jdmorsejdmorse Posts: 8Questions: 1Answers: 1
    edited May 2015

    I think that error is just caused by having an empty table with no data to apply options to. If I populate the table with data, that error will go away. The option being applied is custom sorting for time by AM/PM.

    http://i.imgur.com/37Nnlmx.png

    Just came across: https://www.datatables.net/forums/discussion/27127/how-to-pass-a-php-form-variable-to-server-processing-for-use-in-where-clause

    I think this is the same thing I am working on. I will go over this. Thank you.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Can you show me the JSON that is being returned that is causing the error and also the Javascript code please? I might be able to determine what the error is with more information.

    Allan

  • jdmorsejdmorse Posts: 8Questions: 1Answers: 1
    edited July 2015 Answer ✓

    Allan, sorry for such a delayed response.

    I solved my issue by storing the user as a session variable. Then using ->where( 'Driver', $_SESSION['user'] ) in the PHP AJAX file.

This discussion has been closed.