We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14721
    • 16 Posts
    Anyone know how to add a checkbox or radio column to the Datagrid widget?
    • Garry Nutting Reply #2, 18 years ago
      Hi jorge,

      Okay, in Column Types add the following (substituting the relevant column names for your own from the query etc.):

      template:<input type='radio' name='myname' value='[+id+]' /> [+value+]


      And then add ’template’ into the ’Field Names’ where you would like the radio/checkbox to be displayed in the datagrid output. (Of course, you can call the field anything you like - you don’t have to use ’template’)


      Hope that helps, Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 6841
        • 61 Posts
        Sorry for butting in on this thread, but I’ve been trying to do a similar thing using the "template" field type for making a "mailto" link from an email address. The problem I’m having is that wherever I have a "=" in my template string, it gets converted to "%3D" in the HTML source when the page is rendered. This, of course, makes it so that my link doesn’t work.

        Any ideas?

        Jorge, did you try garryn’s suggestion? Did it work for you?
          Dave
          • 14721
          • 16 Posts
          Unfortunately, I did not get this to work. The column is empty when displayed. I made a screen shot of my config, in case someone can see a silly mistake:

          Here is the exact text in "Column types":

          radio:<input type='radio' name='pick' value='[+id+]' /> [+name+]


          -------

          For what it’s worth, I did have some luck with this hack. But it’s pretty horrible, but it might work for the mail link...

          @SELECT CONCAT(CONCAT("<input name=pick type=radio value=’", pl.id),"’ \>") as id, pl.is_shared, pl.name, wu.username FROM astk_portfolios pl, modx_web_users wu WHERE (pl.owner_id = wu.id) and (pl.is_shared);

          • Garry Nutting Reply #5, 18 years ago
            Oops, probably my fault - I made an error on my last post embarrassed. I’ve just had a closer look at this ...

            You need to specify the column type as follows:
            template:<input type='radio' name='pick' value='[+id+]' />


            i.e. ’template’ is a specific function of the datagrid and not the name of the field/column as I previously thought.

            Give that a go and let me know if it works, I’ve only ever used the datagrid in php code and not through the widget but it should behave the same in terms of the values that have to be set.

            Cheers, Garry

              Garry Nutting
              Senior Developer
              MODX, LLC

              Email: [email protected]
              Twitter: @garryn
              Web: modx.com
              • 14721
              • 16 Posts
              Bingo. That worked fine after I fixed (my type) of forgetting type="radio" in the INPUT tag.

              A follow up question...

              Is the datagrid documented anywhere (besides the online docs on this site)? It seems very powerful. I tried to hunt down the code for it so I could see what all the "field" do, but didn’t have much luck.

              Thanks for your quick response.

              -- Jorge.
                • 14721
                • 16 Posts
                I take it back. I have the same problem with the = getting converted to %3d that Dave mentioned above.

                Html ends up all messed up for the radio like:

                <input type%3dradio name%3dpick value%3dnum1 >
                
                • Garry Nutting Reply #8, 18 years ago
                  Quote from: jorge at Apr 11, 2006, 09:53 PM
                  Is the datagrid documented anywhere (besides the online docs on this site)? It seems very powerful. I tried to hunt down the code for it so I could see what all the "field" do, but didn’t have much luck.
                  It definitely comes in useful sometimes smiley As far as I know, there’s no more documentation for this ... I’m learning more about it every time I use it so I’ll make sure I capture anything I learn and post back in the forums - might help out a bit (or may not, but I’ll post anyway wink ).

                  As for the encoding problems - could you please log it in the bug tracker.

                  Thanks, Garry
                    Garry Nutting
                    Senior Developer
                    MODX, LLC

                    Email: [email protected]
                    Twitter: @garryn
                    Web: modx.com