Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your question.

    Unfortunately, this is not easily possible. You would need to directly access the TablePress PHP classes for this.

    Now, may I ask why you would like to do this? What is your goal here?

    Thanks!
    Tobias

    Thread Starter rictans

    (@rictans)

    As I understand how TablePress works, a table can be created and the entries in the table has to be manually entered. Is it possible to create the table first with no entries, then run PHP/SQL code that is in a page template, to populate the table?

    Thanks,
    Wordpress rookie πŸ™‚

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    yes, that is correct. The table has to be filled manually by typing in the contents, or by importing a file. In theory, you could use the internal TablePress PHP functions to fill a table programmatically, but I don’t recommend that.

    Instead, please tell me, why you want to do this, instead of for example directly creating <table> HTML code in your page template. Why do you want to fill a TablePress table like this?

    Regards,
    Tobias

    Thread Starter rictans

    (@rictans)

    I am trying to build points tracking system whereby earned or used points are displayed on a table like this:

    Date Description Debit Credit Balance

    Similar to a bank’s account activity web page. So I would have “transactions” in a MySQL table… run the SQL for a particular user, then display them in a table.

    Instead of creating my own HTML, I am looking for a plugin that can display the info, have paging, search and sort functions.

    Aside: Table borders are set in a css and not a TablePress option? (I’ll admit I am lazy! πŸ™‚

    Thanks.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ok, thanks for that explanation. So, basically, what you want is a HTML table with sorting, pagination, etc., but you don’t really need the “Edit” screen to enter the data, as that will be done in your mySQL DB?
    Then it will be much easier to just use PHP (in your page template) to create the <table> HTML and manually load the DataTables JavaScript library from http://www.datatables.net and integrate that with your table. This is the same library that TablePress uses to make tables sortable, searchable, and for the pagination.

    (And yes, borders and all other styling is set via CSS, without options.)

    Regards,
    Tobias

    Thread Starter rictans

    (@rictans)

    Thanks for your help and advice… much appreciated. Particularly your prompt replies…

    There is a plugin called “dbview”. Are you familiar with it? It says:

    Presents the results of a database query in a table. The query can be saved as a view which can then be embedded in any post using a shortcode.

    I haven’t tried it yet but will have a look.

    I surely take a look at datatables.net but I am not javaScript literate… another thing to learn. I am pressed for time so I am looking for the easy route.

    Again… thanks Tobias.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no, I haven’t heard of that plugin, but it sounds interesting, and I will take a look at it. Thanks for mentioning that!

    You don’t really need to be JavaScript expert, the integration is very easy. There’s even a small tutorial here:
    http://datatables.net/blog/Getting_started_with_DataTables%3A_First_steps
    And trust me, this is the “easy route” here πŸ™‚ Everything else is more error-prone and will take more time to integrate.

    Best wishes,
    Tobias

    Thread Starter rictans

    (@rictans)

    Thanks for the link. I have been looking at that already trying to figure things out. According to WordPress documentation:

    Query noConflict wrappers

    Note: The jQuery library included with WordPress loads in “no conflict” mode. This is to prevent compatibility problems with other javascript libraries that WordPress can load.

    In “no-confict” mode, the $ shortcut is not available and the longer jQuery is used. For example:

    $(document).ready(function(){
    $(#somefunction) …
    });

    Becomes:

    jQuery(document).ready(function(){
    jQuery(#somefunction) …
    });

    So this means I don’t have to add the following in header.php:

    <script type=”text/javascript” charset=”utf-8″ src=”/DataTables/media/js/jquery.js”></script>

    Correct?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    exactly, loading jQuery manually is not necessary. Only if it is not loaded already (e.g. by another plugin), which you can check in the HTML source of the generated page, you should do something like

    wp_enqueue_scripts( 'jquery' );

    in your page template.

    Also, that codex description about the “no conflict” mode only leads to one change (in the tutorial). The line

    $(document).ready( function () {

    needs to be changed to

    jQuery(document).ready( function($) {

    Regards,
    Tobias

    Thread Starter rictans

    (@rictans)

    OK, I am embarrassed… I don’t think WordPress’ jQuery is running in my installation (which is probably not true so there must be something wrong with what I am doing). In my header.php I have added the following:

    <!– ———- My additions to header.php below———- –>

    <script type=”text/javascript” charset=”utf-8″ src=”http://www.sohopoints.org/wp-includes/js/DataTables/media/js/jquery.dataTables.js”></script&gt;

    <?php wp_enqueue_script(“jquery”); ?>

    <style type=”text/css” title=”currentStyle”>
    @importhttp://www.sohopoints.org/wp-includes/js/DataTables/media/css/demo_table.css&#8221;;
    </style>

    <script>
    jQuery(document).ready(function() {
    alert(‘hi’);
    });
    </script>

    <script type=”text/javascript”>
    jQuery(document).ready(function(){
    jQuery(‘#table1_id’).dataTable({“aaSorting”:[],”bSortClasses”:false,”asStripeClasses”:[‘even’,’odd’]});
    });
    </script>

    <!– ———-My additions to header.php above———- –>

    I can’t get DataTables running πŸ™

    Can you have a quick look, the site is not in “production”… thank you: http://www.sohopoints.org/datatable-page/

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no, jQuery is loaded, but only after the browser tries to run your JavaScript code. And at that time, jQuery is not yet defined, so that script errors are the result.

    Just try putting everything except the CSS and the wp_enqueue_script() call to the footer.php.

    Well, actually putting this in header.php and footer.php is not a good idea, because then this would be executed on every page and not only on that with the table. Didn’t you say that this is a page template? In that case, everything except styling and wp_enqueue_script() should go near the bottom of the page template.

    Regards,
    Tobias

    Thread Starter rictans

    (@rictans)

    OK… page template… I give it a try… thanks.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    yes, that will help to load the JavaScript code only in relevant places. And that’s also the place where you can put the PHP code that generates your <table> HTML code from the data that you query from the database.

    Regards,
    Tobias

    This may not be related, but I’m interested in using PHP to update Tablepress tables from a CSV on my server.

    I use tables as a product list.

    My staff regulalry update the excel files with new information and prices then export and manually upload them.

    It would be great to be able to dynamically load them from a server based CSV and skip all that manual uploading.

    Thread Starter rictans

    (@rictans)

    Hi Bloggorus,

    Sounds like you are using Excel as a database, which its not. Why don’t you create table(s) on the MySQL database (I’m guessing you are using MySQL) and import the data once. But before doing that, you would need to create Add, Delete, Modify web pages to manage the information. It would be similar to what WordPress provides for managing users. I haven’t checked plugins that may meet your needs. There may be one or hire a developer if you are not one yourself. Add, delete and modify stuff is pretty standard. Then you may want something for reporting what you have in the table(s) once in a while too. Anyways… just some comments without knowing exactly what you/your business does (a disclaimer πŸ™‚ )

    I like Tablepress and want to use it on my site(s).

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Import CSV with PHP instead of Manually?’ is closed to new replies.