No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    dynamic columns declaration in q-table ?

    Help
    2
    3
    1800
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jitendra16 last edited by

      In q-table we need to declare columns object, but in my case user is uploading csv file and i need to show all columns(columns names are user dependent) in q-table. I don’t want to use Markup table because in need rich features(selection, sorting, filtering) of q-table. Any clue how this can be done?

      1 Reply Last reply Reply Quote 0
      • C
        chyde90 last edited by chyde90

        The columns object doesn’t need to be static.
        You can always modify it or generate it dynamically, for example as a computed property.

        Maybe this will give you an idea:

        computed: {
          columns() {
            return this.columnNamesFromCsv.map(columnName => {
              return {
                name: columnName,
                label: columnName,
                align: "left",
                sortable: true,
                field: row => row[columnName]
              };
            });
          }
        }
        

        Note that the field attribute is a function to extract the cell value from the row.

        I’m assuming you parse the CSV into a Javascript object.
        This all depends on how your data looks, of course.

        J 1 Reply Last reply Reply Quote 1
        • J
          jitendra16 @chyde90 last edited by

          @chyde90 Thanks for clue. I achieved this following way

          columns() {
                return Object.keys(this.parsedJsonArrayOfObjectsFromCsv[0]).map(key => {
                  return {
                    name: key,
                    label: key,
                    align: "left",
                    sortable: true,
                    field: key
                  }
                })
              }
          
          1 Reply Last reply Reply Quote 1
          • First post
            Last post