Categories > TinyButStrong general >

mergeblock array -> result is not sortable

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Vincent
Date: 2011-07-02
Time: 16:34

mergeblock array -> result is not sortable

Hi,

Every few months I get a sudden urge to work on my app, and I'm always glad to come back here to see what has changed in TBS. (I will be looking to the new PDO-feature!)

I'm trying to get my tables sortable. Since I'm using jQuery already, I have tries 4 or 5 jQuery plugins already, but none of them seem to work, so I guess it might be related to TBS, or the way I'm using TBS. Most of my tables are built with
    $TBS = new clsTinyButStrong;
    $TBS->LoadTemplate("templates/bank_overzicht.htm");
        $TBS->MethodsAllowed = true;
        $F = new Finance;
        $TBS->MergeBlock("bank","array", $F->get_transaction_list_array());
    $TBS->Show();
Template-side, I make up a table as it should, with all bells and whistles. This works to get a simple table, but I cannot get them to sort.
    <table class="sortable" width="940">
        <thead>
            <tr>
                <th width="100">Datum[bank;block=tr;when [bank.#]=1]</th>
                <th width="100">Bedrag</th>
                <th width="150">Interne Rek</th>
                <th width="*">Mededeling</th>
                <th width="60">Afschrift</th>
                <th width="75">Dossier</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>[bank.date;block=tr]</td>
                <td>[bank.amount;frm='€ 0,00']</td>
                <td>[bank.acc_int]</td>
                <td>[bank.comment_1]<br />[bank.comment_2]</td>
                <td>[bank.doc_nr]</td>
                <td><a href="?p=dos&s=[bank.dos_nr]">[bank.dos_nr]</a></td>
            </tr>
            <tr>
                <td colspan="6">[bank;block=tr;nodata]Geen transacties</td>
            </tr>
        </tbody>
    </table>

One of the plugins (dataTables) can handle server-side code: you provide it with a json file and some settings, and it creates the table for you. So now I'm thinking: how should I provide the dataTables-code in my <head>-template with the json-file through TBS? Or am I making things overly complex and should it work much easier?
By: Skrol29
Date: 2011-07-03
Time: 00:28

Re: mergeblock array -> result is not sortable

Hi,

If you cannot make jQuery to sort the HTML table, this is a jQuery problem.
Take a stable HTML result of your TBS merge, and start your jQqery debugging from this base.
When you'll found the solution, you'll see if there is something to change in the template.

Now if you want tp use the dataTable plug-in that requires only json data, then you don't need TBS at the server side for this. The PHP function json_encode() can format any data into json. I guess that this plug-in need only the data, the header information should probably be a configuration to give to the Table Builder.


By: Vincent
Date: 2011-07-03
Time: 11:01

Re: mergeblock array -> result is not sortable

I like your very fast replies, thank you very much!

I have taken your suggestion and made a static table, only to see that everything is working for dataTables. But if I provide the data dynamically with TBS, then it only formats the table and adds a 'no data in table' - functions like filtering, sorting etc. are not available.

Will look into the json-thing.

THX again!
By: Vincent
Date: 2011-07-03
Time: 13:00

Re: mergeblock array -> result is not sortable

Since jquery.dataTable did not seem to work well with TBS supplying the table through mergeBlock, I investigated the json-possibility, and it looks very promising.

It is much faster because the pagination works server-side and so the script doesn't have to fetch all 4433 rows from my dbase. This is how I'm using it now:
Init:
        $TBS = new clsTinyButStrong;
        $TBS->MethodsAllowed = true;
        $F = new Finance;
        $TBS->ObjectRef["F"] =& $F;
        $TBS->LoadTemplate("templates/bank_overzicht.htm");
Template:
            <table id="overzicht" width="940">
            </table>

        <script type="text/javascript">
            $(document).ready(function() {
                $('#overzicht').dataTable({
...
                    "aaData"    : [onshow.F.get_transaction_list_json;htmlconv=no],
...
                });
            });
        </script>
The *only* thing keeping me from getting this to work perfectly together, is that TBS converts the first character from my json_encode() (being '[') to &#91;

I have seen someone suggesting on the forum changing htmlconv to 'js' or try some other values, but that doesn't work for the first character. Upgrading to TBS 3.7 also didn't work.

Is this a bug or should I do something else?
By: Vincent
Date: 2011-07-04
Time: 12:10

Re: mergeblock array -> result is not sortable

Bug apparently: if I work around it by removing the first '[' and adding it in the template, then everything works smoothly. The workaround is not that hard, so it doesn't really bother me (but it is a bug ;))
By: Sebastian
Date: 2011-12-20
Time: 09:53

Re: mergeblock array -> result is not sortable

This is a feature, not a bug. And there is a solution to it. Just found it here: http://www.tinybutstrong.com/support.php#faq_protect