We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15001
    • 697 Posts
    Hi,

    I have a table looking like this, the last columns being boolean values :

    Object Indoor Outdoor Restaurant Factory
    ----- ------ ------- --------- ------
    Le Gatronomique 1 0 1 0
    The Watch Maker 1 0 0 1

    Now, I would like to list with the Datagrid widget all records that meet the Indoor and Restaurant criteria, but with only one column : the object name.

    @SELECT `objets`, `indoor`, `restaurant` FROM my_table WHERE (indoor=1 AND restaurant=1)  

    Questions :

    1) Is there a way to only have the "Object" column diplayed by the Datagrid ?
    Should I make a SELECT over a SELECT, or a VIEW ? (I’m rather newbie with MySQL.)

    2) Is there a way to remove the column headers outputed by the Datagrid ?

    3) Is there a way to make that the Datagrid displays outputed records in more than one column ?
    (This is because my column is rather thin.)

    Thanks for any help.
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      I wrote a short page on this in the Wiki:
      http://wiki.modxcms.com/index.php/Data_Grid_Widget

      If you want to do custom formatting, you’re better off working with a Snippet... it’s more difficult, but the flexibility can’t be beat. The widgets are nice, but not very customizable.

      To select only the one column, you could simply change your query:
      @SELECT `objets` FROM my_table WHERE (indoor=1 AND restaurant=1) 


      You might be able to "mute" the headers by using MySQL’s "as"... try something like this:
      @SELECT `objets` as ``, `indoor` as ``, `restaurant` as `` FROM my_table WHERE (indoor=1 AND restaurant=1) 


      Or maybe use "as ` ` or similar... kinda a janky work-around, but it might work for you.

      You could use the "as" statement to extend the width of your column header, e.g.
      @SELECT `short` as `long long long long column label` FROM my_table


      Hope this helps.
        • 15001
        • 697 Posts
        @Everett : Thanks. I observed that using as`` (with empty field name does not work, but that as ` ` works, as long as   is used as field name in the Datagrid TV settings.
        The easier solution is however to let the SELECT `objets` FROM table unchanged (without as) and let the column name blank in the Datagrid TV.

        I could set the header appearance to invisible with this Column Header style :
        background:none;font-size:1pt;line-height:1pt;height:1px;

        Of course, using a Column Header class would be better if the Datagrid is called many times.

        Still have small problem with quotes. My table is built from a CSV file with VARCHAR values like this one :
        Restaurant "Le Gastronomique", Somecity

        The Datagrid outputs it as
        "Restaurant ""Le Gastronomique"" Somecity

        I cannot ask my customer to escape the quotes.
        Does someone have idea how to avoid this problem ?