WordPress.org

Forums

TablePress
[resolved] PHP in table to load data dynamically. How does it work ? (6 posts)

  1. madebyj
    Member
    Posted 1 year ago #

    Dear Tobias,

    First of all, thank you very much for your plugin. I am just starting with it but I can see how powerful it is :)

    I have some data from endusers I would like to restitute in a dynamic way. Let's say a user A has 3 cars (mercedes, dacia, renault) and a user B has 2 cars (alfa, bmw).

    My goal is to achieve a page loaded by a connected user which display only his own data.

    1 - I am creating a table with a header line and a body line. I fix values of the header line (cars).
    2 - I insert my php code in the body line

    How can I set things so a new line is automatically created after each entry ?

    In that way :

    User A :
    Cars
    mercedes
    dacia
    renault
    User B :
    Cars
    alfa
    bmw

    Thank you very much for any help you can provide. Hope it works :)

    Ben

    PS : I also had the issue PHP not loading without the instruction convert_line_breaks=false. Just in case it helps you :)

    https://wordpress.org/plugins/tablepress/

  2. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    thanks for your post, and sorry for the trouble.

    I'm not really sure if I understand. You will probably just have to print that new line by printing the HTML <br /> tag.

    Regards,
    Tobias

  3. madebyj
    Member
    Posted 1 year ago #

    Dear Tobias,

    By using <br> I come up with a single line. So to get back to my example. I will have :
    User A :

    line 1 (header) Cars
    line 2 (body) mercedes
                  dacia
                  renault

    I am loosing "sort" functionnality for e.g. as I have all my data in the same line.

    I am looking for this result :
    User A :

    line 1 (header) Cars
    line 2 (body) mercedes
    line 3 (body) dacia
    line 4 (body) renault

    I hope it is clear :)

    Ben

  4. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Ben,

    ah, ok. So you want to create real table rows here.
    To be honest, I don't really see the point of using TablePress here then. Instead, just use your PHP code to render the full HTML table.
    You can then simply use the DataTables JS library for the sorting directly (that's the library that TablePress uses). See http://next.datatables.net/ for information on that.

    Regards,
    Tobias

  5. madebyj
    Member
    Posted 1 year ago #

    Dear Tobias,

    You are right and it worked for me but there is something I do not understand. Maybe you have an easy answer to that...

    Tablepress plugins is installed on my wordpress but if I want to use function of DataTables, I have to load all the libraries. Is it not strange ?

    I have tried a lot of diferent ways (header, enqueue etc.) and the only way I found out is to write this at the begining of my wordpress page:

    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.0-rc.1/css/jquery.dataTables.css"><script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script><script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.0-rc.1/js/jquery.dataTables.js"></script>

    Maybe you can advice me on this.

    Also TableTools is not showing...

    <script>
    $(document).ready( function () {
        $('#sommets').DataTable({
    		"sDom": 'T<"clear">lfrtip'
    	} );
    } );
    </script>

    Thank you for your help :)

  6. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    you don't really have to load all the libraries from an external source, you can also include the ones that TablePress ships with.

    Using a custom wp_enqueue_script call should be the best here, for independence from TablePress.

    Regards,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • TablePress
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic