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 MODx fans,
    If you’re like me, you have bunches of table data to display in columns and rows. We have the Datagrid Widget for that purpose, and it’s pretty cool.

    A feature was added to it, Column Types, whose purpose was to format data in a column, for bold and italic and that sort of thing.

    However, sometime ago folks were asking about using URL’s in there, because they tried it and didn’t get good links. The upshot is that the "equal sign" was getting clobbered, and this does matter in URL’s. wink I’ll spare you the gory details, but I found some code that encodes and decodes the "equal sign", and I’m sure that this is highly useful for something. I’ll leave that to folks who enjoy the intricacies of character encoding.

    I believe I’ve found a solution. For those of you who don’t mind editing some code, in datagrid.class.php at around line 120, you’ll see the following lines. My patch is marked in red. I prefer not to use hard-coded patches, but this one keeps the fix very small and doesn’t risk harming other code.

    ------------------------------------------
    case "template":
    // replace [+value+] first
    // problem is ’=’ is being changed to ’%3D’ before it gets here.
    $type_format = str_replace(’%3D’,’=’,$type_format);

    $value = str_replace("[+value+]",$value,$type_format);
    // replace other [+fields+]
    if(strpos($value,"[+")!==false) foreach($row as $k=>$v){
    $value = str_replace("[+$k+]",$v,$value);
    }
    break;
    -------------------------------------------------

    Reminder: In the Datagrid, you put code like the following into the Column Type. In the following example, my database field is enclosed by plus signs. Notice that I began the line with 2 commas. This is because I want the formatting in the third column, so I’m using the commas to skip the first two. I had a couple of goofs before I figured that out. Similar code can be used for email or other types of links.

    ,,template:<a href=’http://[+website+]’>[+website+]</a>

    I hope you enjoy it! Samba

    PS: I’ve also been getting excellent use out of Jason’s Maketable snippet for more flexible formatting.
      MODx and Wordpress development
      Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4
      • 10487 MODX Staff
      • 1,535 Posts
      Hi samba,

      I have just investigated the root cause of this bug and found it to be in the decodeParamValue() function in tmplvars.format.inc.php (found in manager/includes)

      The problem is an unnecessary escaping of the % character in the string replacements, preventing the function from finding any matches:
      function decodeParamValue($s){
      		$s = str_replace("\%3D",'=',$s); // =
      		$s = str_replace("\%26",'&',$s); // &
      		return $s;
      	}
      


      Just remove those backslashes and the replacement is carried out as desired. I will get this submitted to SVN to ensure it makes the next release.

      Thanks,
      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 26016
        • 561 Posts
        Quote from: garryn at Sep 01, 2006, 02:46 PM

        Hi samba,

        I have just investigated the root cause of this bug and found it to be in the decodeParamValue() function in tmplvars.format.inc.php (found in manager/includes)

        The problem is an unnecessary escaping of the % character in the string replacements, preventing the function from finding any matches:
        function decodeParamValue($s){
        		$s = str_replace("\%3D",'=',$s); // =
        		$s = str_replace("\%26",'&',$s); // &
        		return $s;
        	}
        


        Just remove those backslashes and the replacement is carried out as desired. I will get this submitted to SVN to ensure it makes the next release.

        Thanks,
        Garry
        Garry,
        Good catch!!! I appreciate your checking into that. I actually did hunt down that code above, and realized that this was part of the weirdness scenario.

        It’s funny that, as I mentioned, my first thought was that the decode function was probably used everywhere, so I was loathe to touch it, and it didn’t occur to me that it could be wrong.

        BTW, this is my second published fix of the Datagrid. (the other was getting the "this row is empty" message to work right, which was more clearly a problem in the Datagrid code). I think I’ll become a Datagrid consultant, as well as for MakeTable, which I’ve been tweaking for my evil needs. grin

        Thanks again, Samba
        PS: I’m looking forward to the 1.0 release, whenever that may be, and wish you the best on that.
          MODx and Wordpress development
          Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4
          • 2472
          • 151 Posts
          Thanks to this post ( and a few others ;-), I just managed to get what I wanted: including a hyperlink in a simple datagrid that passes the value of a db column ( ’id’ in the example) to a fixed document ( 75) using a variable ( ’station’).

          The db column is the second one in the request, hence the leading ’,’ in the code.

          [tt],template:<a href=’[~75~]&station=[+id+]’>[+id+]</a>[/tt]

          Works in 0.9.5, not sure about prior versions...
            A thing of beauty is a joy forever ( John Keats)
            • 26016
            • 561 Posts
            Quote from: Avander_be at Mar 03, 2007, 10:47 AM

            Thanks to this post ( and a few others ;-), I just managed to get what I wanted: including a hyperlink in a simple datagrid that passes the value of a db column ( ’id’ in the example) to a fixed document ( 75) using a variable ( ’station’).

            The db column is the second one in the request, hence the leading ’,’ in the code.

            [tt],template:<a href=’[~75~]&station=[+id+]’>[+id+]</a>[/tt]

            Works in 0.9.5, not sure about prior versions...
            Avander,
            Glad to hear it! Since I made that post, I ended up getting the Datagrid to work very nicely, with URL’s, email addresses, etc., and changing the size of text in a cell where appropriate. It’s a really nice piece of code, all in all.

            MakeTable has a plethora of great ideas in it, no mistake about it. But I found that the Datagrid code is so well-organized and easy to follow, that I ended up sticking with it. I’ve been away from here for a couple months, so both of them may have evolved further, for all I know.

            BTW, as I got fancier with templates in the Datagrid, there were situations where my template edits from the admin panel gave me unpredicted results. When you’re doing links, obviously you end up with characters other than letters, like "greater than" and "less than" signs, for instance. When I’d code these into the template, sometimes they would be saved as character entities that I didn’t expect, and the links wouldn’t work. I think this has something to do with UTF and other character-translation sorts of things.

            My workaround was to edit the database tables and make the template changes there. This way the admin interface was not there to "interpret" was I was typing into something else, and then my links worked! Somewhat cumbersome, but successful.
              MODx and Wordpress development
              Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4