We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26016
    • 561 Posts
    Hi All,
    I have a site in which I need to show large amounts of data. I’ve been using columns and rows, and have a heavily tweaked version of Datagrid to do that. Essentially, I am using one row per listing, and each row uses several columns/fields.

    I tried to upgrade my site, and the datagrid part of the site was totally trashed. As far as I could tell, the datagrid code had been changed so much that I couldn’t even begin to figure out how to thread in my modded code. So since then, I’ve been getting along with a very out-of-date version of MODx so that my site will still function.

    This still concerns me somewhat, even though I’ve tried to use decent security practices and the like. I’m also having minor annoyances, such as needing to use old versions of snippets; I’ve gotten spoiled using the nice new versions on other sites!

    But I’m reconsidering this and wondering about other ways to show the data. How are you folks handling displaying loads of tabular data in the latest version of MODx?

    Thanks!
    Samba
      MODx and Wordpress development
      Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4
      • 10226
      • 412 Posts
      Not sure if this will be worthy of modifying for your masses of data, but have a look here.

      http://veerle.duoh.com/blog/comments/a_css_styled_table_version_2/
        • 26016
        • 561 Posts
        Quote from: fruitwerks at Sep 10, 2007, 08:43 AM

        Not sure if this will be worthy of modifying for your masses of data, but have a look here.

        http://veerle.duoh.com/blog/comments/a_css_styled_table_version_2/
        Hi,
        That looks pretty nice, a great way to get table data looking really good!

        Let’s see, to do that in MODx, maybe I could make a TV, use some kind of @Binding to get my data, and work out a template to style it with a chunk(??). I hope others have ideas on that particular issue.

        I suppose another question would be, are people having success using the Datagrid in 9.6 these days?

        Thanks again!
        Samba

          MODx and Wordpress development
          Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4
          • 10226
          • 412 Posts
          I have never heard of datagrad, but when i heard that and "column and row data" I immediately thought of that link.

          Not sure what topic it was, but there was a snippet to count iterations. It was only a few lines of code. I’m sure something similar could be applied to what you need. I’m not a code guru but I can say this right now - we will need some more information about your data and how it is populated and stored.

          Have fun!
            • 22303 MODX Staff
            • 10,725 Posts
            I’ve personally avoided the datagrid code like the plague. I’ve used several approaches to producing tabular data output though, using the MakeTable class I contributed a while back, or just looping through db result sets in a snippet and merging each row with a chunk containing placeholders for the fields. This latter approach is my favorite, as it provides an easy way to manage and quickly customize the output of the individual rows.

            Here is a simple example of getting and looping through data rows with the DBAPI and using the setPlaceholder() and parseChunk() functions:
            <?php
            $output= '';
            $rowChunkName= 'tableRowChunk';
            $sql= 'SELECT * FROM `table_of_data`';
            $rs= $modx->db->query($sql);
            if ($rs) {
                foreach ($modx->db->getRow($rs) as $row) {
                    $modx->placeholders= array_merge($modx->placeholders, $row);
                    $output.= $modx->parseChunk($rowChunkName, $modx->placeholders, '[+', '+]');
                }
            }
            return $output;
            ?>


            You can then create your table structure and simply place this snippet where your rows should be output.
              • 7231
              • 4,205 Posts
              OpenGeek: that is a great tip.
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 26016
                • 561 Posts
                Jason,
                Thanks!!! Great idea. That looks pretty easy to implement. I’ll have to roll up my sleeves and figure out how to handle paging, but I suppose I can handle that with some thought.

                I had tried your excellent Maketable, and there’s great code everywhere in there, but when I tried to modify it, every change I made borked 4 other places in the code, so I finally gave up. I think your above idea will work great, and between that and FW’s ideas for styling, this can look really look good.

                I’m sure others can understand when you get used to a particular tool, and then keep using it beyond all reasonableness - sort of digging further and further, and finally you hit a dead end. I guess that’s what I did with the Datagrid here, which was just easy enough to tweak. It’s also funny how many ways there are to do something before you actually know anything. smiley That speaks to the flexibility of MODx.

                As always, the smartest people inhabit this place!
                Thanks!!!! Samba
                  MODx and Wordpress development
                  Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4
                  • 6726
                  • 7,075 Posts
                  Missed that one, luckily I read another thread which pointed to here and I am glad, certainly will have a use for it !
                  Thanks Jason smiley
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l&#39;outil id
                    • 23377
                    • 5 Posts
                    Hi,

                    i’m searching for a simple solution to display data in a table without using the datagrid widget. So, this post is exactly what i’m looking for, but i get the following error by using the postet "looping through code":
                    « MODx Parse Error »
                    MODx encountered the following error while attempting to parse the requested resource:
                    « PHP Parse Error »
                     
                    PHP error debug
                      Error: 	array_merge() [function.array-merge]: Argument #1 is not an array	 
                      Error type/ Nr.: 	Warning - 2	 
                      File: 	/var/www/dedoba-neu/html/v1/manager/includes/document.parser.class.inc.php(766) : eval()'d code	 
                      Line: 	8	 
                     
                    Parser timing
                      MySQL: 	0.0031 s	(4 Requests)
                      PHP: 	0.0547 s	 
                      Total: 	0.0578 s
                    

                    Any ideas? I am..let’s say a "half-newby". So, a little more detailed describtion on how to use the code would be nice.

                    Thank you!