We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22303 MODX Staff
    • 10,725 Posts
    Attached is a MakeTable class (and sample snippet) I’ve been using on some projects to produce tables with pagination, sortable columns, some limited row form controls, and several ways to provide links/actions to the cells and cell content.

    If nothing else it is a good example use of the DBAPI, and some other MODx features like Placeholders. Hope it is useful to someone.


    GETTING STARTED:

    • extract the files in the maketable.zip file to /assets/snippets/maketable/
    • I used some make believe tables for this example, so you’ll need to create your own snippet based on the maketable.example.snippet.txt file that is included to query data from your own database tables
    • don’t forget to include the call to your snippet and the placeholder you assign the output to (unless you decide to just return the value from your snippet) somewhere in your template/document content/TV’s, e.g.
    ...
    [[MyTableSnippet]]
    <div id="tableContainer">[+myTablePlaceholder+]</div>
    ...


    • refer to the comments I’ve included in the example snippet and class files, and feel free to modify and use these however you want to

    Comments and questions welcome.
      • 16886
      • 40 Posts
      Quote from: OpenGeek at Dec 06, 2005, 07:34 PM

      Comments and questions welcome.
      Looks like the missing part of the ’DataGrid’...
      I will try out and post my results ( or questions )
      Thanks for sharing

      1st Test:
      Generated the Table in the Example
      Created the Snippet ( the INCLUDE File Name in the Example for this ZIP-File is not correct:
      assets/snippets/maketable/maketable.class.inc.php = assets/snippets/maketable/maketable.class.php )
      Created a Document
      Content only: [[mytab]]

      and ... an empty Webpage no result-table, hmmm... SQL checked by MySQLAdmin, where is the result?


      LeftHanded
        I love ModX!
        • 16886
        • 40 Posts
        ... and ... an empty Webpage no result-table, hmmm... SQL checked by MySQLAdmin, where is the result?
        Fixed the problem by myself.
        The Snippet-Name and the Placeholder name are case-sensitive !

        Thank you for this snippet i will use it.
        LeftHanded
          I love ModX!
          • 4095
          • 372 Posts
          I have changed the databse calls from "industries" to "modx_courses" so it can pull data from an exisitng table.

          However I get the following error:

          « MODx Parse Error »
          MODx encountered the following error while attempting to parse the requested resource:
          « Execution of a query to the database failed - Table ’emanz_modx.subindustries’ doesn’t exist »
          SQL: SELECT i.*, COUNT(DISTINCT aoe.id) AS area_count FROM modx_courses i LEFT JOIN subindustries si ON si.industry_id = i.id GROUP BY i.id ORDER BY id DESC LIMIT 0, 25

          This would appear related to the following section, which I do not understand. not sure what the line ""LEFT JOIN subindustries si ON si.industry_id = i.id " ." actualy does.

          // execute the main table query with MakeTable sorting and paging features
          $query= "SELECT i.*, COUNT(DISTINCT aoe.id) AS area_count " .
          		"FROM modx_courses i " .
          		"LEFT JOIN subindustries si ON si.industry_id = i.id " .
          		"GROUP BY i.id" . $objTable->handleSorting() . $objTable->handlePaging();
          if ($ds= $this->db->query($query)) {
            [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
            Admin Sandbox Login: sandbox Password: castle
            • 22303 MODX Staff
            • 10,725 Posts
            Just remove that part of the query; this was just demonstrating a list of industries where each industry had a list of subindustries in another table. This query just provided a count of the number of subindustries that were related to each industry.
              • 17833
              • 28 Posts
              Looks like a very useful class. Do you have any more examples of how it is used? I’d really like to see how the different functions are used. Good job!
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: Machiavelli at Apr 25, 2006, 04:56 PM

                Looks like a very useful class. Do you have any more examples of how it is used? I’d really like to see how the different functions are used. Good job!
                Thanks, though I’m sure I borrowed most of the code or ideas from other peoples code embarrassed

                But anyway, I will try and get around to preparing some more in-depth demonstrations of this class, used in conjunction with my companion MakeForm class to easily build form-based database applications. I used these two classes to replace an application with some 50 different views of about 12 tables developed with a commercial RAD environment last fall, and would make a great case study for both MODx and MakeTable/MakeForm, but unfortunately all of the applications I have developed with these are meant for secure-access only, so I can’t publically demonstrate them. Hopefully I’ll find some time to put together that case study soon with lots of example code...
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I’ll add my vote for this, would be great to see how it’s all put together in a heavy-duty, real-world situation. Even if you just add a blog post one step at a time!
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 17833
                    • 28 Posts
                    That’ll be great to see. And, I’d be happy to help in anyway I can. hosting, setup, whatever. just let me know if i can.

                    Perhaps in the mean time tho you could help me out with a little problem i seem to be having. The links being created for the column headers for sorting are not working for me.
                    I’m getting results like this:
                    "index.php?id=10?orderby=id&orderdir=asc"
                    So, when i click on the links I get a parse error saying that << `10?orderby=id` is not numeric and may not be passed to makeURL() >>

                    The original link for the page was:
                    "index.php?id=10&patid=6"
                    ... so i guess the sortby link should be something like:
                    "index.php?id=10&patid=6&orderby=id&orderdir=asc"

                    Any suggestions?
                      • 7923
                      • 4,213 Posts
                      In quick it seems that this class would work only if FURLs are enabled.. But I might be wrong.


                        "He can have a lollipop any time he wants to. That's what it means to be a programmer."