Search code examples
htmlvuejs2qtableviewquasar-frameworkquasar

How to make add hyperlink to a row of items in Quasar?


I have a Quasar table where there are 5 columns. Among the five columns, I want the 1st column to have a hyperlink to the value that I am getting from an api.

This is my blade.php code -

colModel:[
{name:'name',index:'name', align:'center', sortable:false,  formatter: 'showlink', width:211, cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal;"' }, searchoptions:{sopt:["cn","eq","nc","bw"]}},
{name:'in',index:'in', align:'center', sorttype:'date', datefmt:'Y-m-d H:i:s', searchoptions:{sopt:["cn","eq","nc","bw"]}},
{name:'out',index:'out', align:'center', sortable:true, searchoptions:{sopt:["cn","eq","nc","bw"]}},
{name:'in_comments',index:'in_comments', align:'center',  sorttype:'text', width:211, cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal;"' }, searchoptions:{sopt:["cn","eq","nc","bw"]}},
{name:'out_comments',index:'out_comments', align:'center', sorttype:'text', width:211, cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal;"' }, searchoptions:{sopt:["cn","eq","nc","bw"]}}
]


This is my Vue code -

      visibleColumns: ['name', 'in', 'out', 'in_comments', 'out_comments'],
      columns: [
        { name: 'name', align: 'center', label: 'Name', field: 'name', sortable: true },
        { name: 'in', label: 'In', field: 'in', sortable: true },
        { name: 'out', label: 'Out', field: 'out', sortable: true },
        { name: 'in_comments', label: 'in comments', field: 'in_comments' },
        { name: 'out_comments', label: 'out comments', field: 'out_comments' },
      ],

The name should be wrapped with a hyperlink like this - Name

May I know what can be done to achieve this?


Solution

  • You can also customize only one particular column only. The syntax for this slot is body-cell-[name], where [name] should be replaced by the property of each row which is used as the row-key.

    Example -

    <template v-slot:body-cell-name="props">
            <q-td :props="props">
              <div>
                <a href="https://quasar.dev/vue-components/table#QTable-API" />
              </div>
            </q-td>
          </template>