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 folks,

    I have the project to use DataGrid with a text file.

    What should the text file look like ?
    One row per record and commas to separate the fields ?

    Should the file also have the first row as column headers ?

    I cannot find any tutorial telling about DataGrid with files. Is there any?

    Thanks.
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      I can give you links to the Wiki pages I wrote about this:
      http://wiki.modxcms.com/index.php/%40FILE_Binding
      and
      http://wiki.modxcms.com/index.php/Data_Grid_Widget


      But I know there are plenty of situations (like yours) that I haven’t tested.
        • 26903
        • 1,336 Posts
        The datagrid widget expects either a resource as in a MYSQL resource, or an array.

        I’m not this will work with a FILE binding unless the file is something like :-
        ’name’,’value’
        where ’name’ is the column name(which you have to specify in the datagrid widget itself as a column header) which mimics the array structure ’name’ => ’value’.

        However I’m not sure how FILE works. I doubt if it returns the file as an array, if it returns it as a long string you’ll end up with each character in its own row in the widget, see this thread http://modxcms.com/forums/index.php/topic,30600.0/topicseen.html for more details.
          Use MODx, or the cat gets it!
          • 15001
          • 697 Posts
          Thanks.

          I could import my CSV file into a new table using phpMyAdmin and the "CSV via LOAD DATA" import mode.

          My table structure is : varchar(35), tinyint(1), tinyint(1), tinyint(1)
          where the tinyint fields represent boolean values (1 or 0).

          I’m unable to use the DataGrid widget.

          (skiped)

            • 4310
            • 2,310 Posts
            There was a previous thread about populating the datgrid widget here
              • 9207 ☆ A M B ☆
              • 2,475 Posts
              Check out the Wiki referenced above. There’s also one I wrote about the @SELECT binding and debugging it:
              http://wiki.modxcms.com/index.php/%40SELECT_Binding

              In short, do these 3 things:
              1. Verify that the query runs when executed within MySQL (e.g. phpMyAdmin). The big thing to test here is that the query works... remove MODx from the equation for a moment and check this.
              2. Remove any comments and the trailing ’;’ from the query.
              3. Put the query on a single line and precede it with the @
              4. Make sure the template variable field within the document is not overwriting your @SELECT statement that’s used as the default value.
                • 15001
                • 697 Posts
                Thanks.

                My problem was due to some stupid error: I was calling the TV from the document content, but had forgotten to call the document content from the template! laugh

                Now, the table outputed by the DataGrid displays all the boolean values as ones and zeros.
                Any idea how could I replace the zeros by a " " (non breakable space) character entity ?
                And the ones by some other char like • or a checked checkbox ?

                Maybe some modified SQL command...
                (or jQuery ? or something else ?)
                  • 3749
                  • 24,544 Posts
                  What about making the column type a checkbox?
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 15001
                    • 697 Posts
                    What about making the column type a checkbox?
                    I tried setting the Column type field of the DataGrid to :
                    text;checkbox;checkbox;checkbox
                    then to
                    text,checkbox,checkbox,checkbox
                    and finally to
                    text,Check Box,Check Box,Check Box

                    Nothing changed. Does anyone know the correct syntax ?
                      • 3749
                      • 24,544 Posts
                      Quote from: Jul at Jan 30, 2009, 04:46 PM

                      What about making the column type a checkbox?
                      I tried setting the Column type field of the DataGrid to :
                      text;checkbox;checkbox;checkbox
                      then to
                      text,checkbox,checkbox,checkbox
                      and finally to
                      text,Check Box,Check Box,Check Box

                      Nothing changed. Does anyone know the correct syntax ?

                      The one you didn’t try, of course --  wink

                      According to the Repository page: http://modxcms.com/datagrid-widget.html

                      Text,Checkbox,Checkbox,Checkbox


                      (note the capital letters on Checkbox and Text).
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting