Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!--
  Forked from:
  https://quasar.dev/vue-components/table#Example--Basic
-->
<div id="q-app">
  <div class="q-pa-md">
    <div class="row q-col-gutter-sm">
      <div class="col">
        <q-table
          title="Simple"
          :rows="data"
          :columns="columns"
          row-key="name"
          dense
        >
          <template v-slot:body-cell-actions="props">
            <q-td :props="props">
              <q-btn dense round flat color="grey" @click="editRow(props)" icon="edit"></q-btn>
              <q-btn dense round flat color="grey" @click="deleteRow(props)" icon="delete"></q-btn>
            </q-td>          
          </template>
        </q-table>
      </div>
      <div class="col">
        <q-table
          flat
          bordered
          class="statement-table"
          title="Complex"
          :rows="currencyData"
          :hide-header="grid"
          :columns="currencyColumns"
          row-key="__index"
          :grid="grid"
          :filter="filter"
          virtual-scroll
          v-model:pagination="pagination"
          :rows-per-page-options="[0]"
        >
          <template v-slot:top-right="props">
            <q-input
              outlined
              dense
              debounce="300"
              v-model="filter"
              placeholder="Search"
            >
              <template v-slot:append>
                <q-icon name="search" />
              </template>
            </q-input>

            <q-btn
              flat
              round
              dense
              :icon="props.inFullscreen ? 'fullscreen_exit' : 'fullscreen'"
              @click="setFs(props)"
            >
              <q-tooltip>{{
                props.inFullscreen ? "Exit Fullscreen" : "Toggle Fullscreen"
              }}</q-tooltip>
            </q-btn>

            <q-btn
              flat
              round
              dense
              :icon="grid ? 'list' : 'grid_on'"
              @click="grid = !grid"
            >
              <q-tooltip>{{grid ? "List" : "Grid"}}</q-tooltip>
            </q-btn>
            <div class="q-pa-sm q-gutter-sm">
              
            </div>
          </template>
          
          <template #body-cell-status="props">
            <q-td :props="props">
                <q-chip
                  :color="props.row.status === 'Active' ? 'green': 'red'"
                  text-color="white"
                  dense
                  class="text-weight-bolder"
                  square
                >{{props.row.status}}</q-chip>
            </q-td>
          </template>
          <template #body-cell-action="props">
            <q-td :props="props">
              <q-btn dense flat round color="blue" field="edit" icon="edit" @click="editItem(props.row)"></q-btn>
            </q-td>
          </template>
          <template v-slot:item="props">
            <div
              class="q-pa-xs col-xs-12 col-sm-6 col-md-4 col-lg-3 grid-style-transition"
              :style="props.selected ? 'transform: scale(0.95);' : ''"
            >
              <q-card :class="props.selected ? 'bg-grey-2' : ''">
                <q-list dense>
                  <q-item v-for="col in props.cols" :key="col.name">
                    <q-item-section>
                      <q-item-label>{{ col.label }}</q-item-label>
                    </q-item-section>
                    <q-item-section side>
                      <q-chip v-if="col.name === 'status'"
                        :color="props.row.status == 'Active' ? 'green': props.row.status == 'Disable' ? 'red': 'grey'"
                        text-color="white"
                        dense
                        class="text-weight-bolder"
                        square
                      >{{col.value}}</q-chip>
                      <q-btn v-else-if="col.name === 'action'" dense flat color="primary" field="edit" icon="edit" @click="editItem(props.row)" ></q-btn>
                      <q-item-label v-else caption :class="col.classes ? col.classes : ''">{{ col.value }}</q-item-label>
                    </q-item-section>
                  </q-item>
                </q-list>
              </q-card>
            </div>
          </template>
        </q-table>
      </div>
    </div>
    <q-dialog v-model="show_dialog">
      <q-card style="width: 600px; max-width: 60vw">
        <q-card-section>
          <q-btn round flat dense icon="close" class="float-right" color="grey-8" v-close-popup></q-btn>
          <div class="text-h6">Update Item</div>
        </q-card-section>
        <q-separator inset></q-separator>
        <q-card-section class="q-pt-none">
          <q-form class="q-gutter-md">
            <q-list>
              <q-item>
                <q-item-section>
                  <q-item-label class="q-pb-xs">Currency Name</q-item-label>
                  <q-input dense outlined v-model="editedItem.name" />
                </q-item-section>
              </q-item>
              <q-item>
                <q-item-section>
                  <q-item-label class="q-pb-xs">Code</q-item-label>
                  <q-input dense outlined v-model="editedItem.code" />
                </q-item-section>
              </q-item>
              <q-item>
                <q-item-section>
                  <q-item-label class="q-pb-xs">Buy</q-item-label>
                  <q-input dense outlined v-model="editedItem.buyRate" />
                </q-item-section>
              </q-item>
              <q-item>
                <q-item-section>
                  <q-item-label class="q-pb-xs">Spot</q-item-label>
                  <q-input dense outlined v-model="editedItem.spotRate" />
                </q-item-section>
              </q-item>
              <q-item>
                <q-item-section>
                  <q-item-label class="q-pb-xs">Sell</q-item-label>
                  <q-input dense outlined v-model="editedItem.sellRate" />
                </q-item-section>
              </q-item>
              <q-item>
                <q-item-section>
                  <q-item-label class="q-pb-xs">Symbol</q-item-label>
                  <q-input dense outlined v-model="editedItem.symbol" />
                </q-item-section>
              </q-item>
              <q-item>
                <q-item-section>
                  <q-item-label class="q-pb-xs">Status:Active/Inactive</q-item-label>
                  <q-select :options="statusOpts" dense outlined v-model="editedItem.status" ></q-select>
                </q-item-section>
              </q-item>
            </q-list>
          </q-form>
        </q-card-section>
        <q-card-section>
          <q-card-actions align="right">
            <q-btn
              flat
              label="Cancel"
              color="warning"
              dense
              v-close-popup
            ></q-btn>
            <q-btn
              flat
              label="OK"
              color="primary"
              dense
              v-close-popup
              @click="updateRow"
            ></q-btn>
          </q-card-actions>
        </q-card-section>
      </q-card>
    </q-dialog>
  </div>
  
  <table-wrapper
    title="Table Wrapper"
    :rows="currencyData"
    :columns="currencyColumns"
    row-key="__index"
    v-model:filter="filter"    
    selection="single"
    v-model:selected="selected"
    v-model:pagination="pagination"
    v-model:grid="grid"
   >
    <!--   You can make custom slots for specific view type   -->
    <!--     <template #grid-item-action="props">
          <q-btn dense flat color="primary" field="edit" icon="edit" @click="editItem(props.row)" ></q-btn>        
        </template> -->
    <!--     <template #for-both-action="props">
          <component :is="grid ? 'div' : 'q-td'" :props="props">
            <q-btn dense flat color="primary" field="edit" icon="edit" @click="editItem(props.row)" ></q-btn>
          </component>    
        </template> -->
    <!--     <template #grid-item-status="props">
          <q-chip
            :color="props.row.status === 'Active' ? 'green': 'red'"
            text-color="white"
            dense
            class="text-weight-bolder"
            square
          >{{props.row.status}}</q-chip>
        </template> -->
    
    <!-- different direction than above is to re-use Body cell slot for both views    -->    
    <!-- then use vue's component tag to conditionally render depending on the QTable's view grid/list -->
    <template #body-cell-status="props">
      <component :is="grid ? 'div' : 'q-td'" :props="props">
        <q-chip
          :color="props.row.status === 'Active' ? 'green': 'red'"
          text-color="white"
          dense
          class="text-weight-bolder"
          square
        >{{props.row.status}}</q-chip>
      </component>
    </template>    
    <template #body-cell-action="props">
      <component :is="grid ? 'div' : 'q-td'" :props="props">
        <q-btn dense flat color="primary" field="edit" icon="edit" @click="editItem(props.row)" ></q-btn>
      </component>
    </template>
   </table-wrapper>
</div>


<!-- QTable Wrapper Template -->
<script type="text/x-template" id="table-wrapper">
  <q-table >
    <!-- define default top slots for this wrapper's custom functionalities. -->
    <template v-slot:top-right="props">
      <q-input
        outlined
        dense
        debounce="300"
        v-model="filter"
        placeholder="Search"
      >
        <template v-slot:append>
          <q-icon name="search" ></icon>
        </template>
      </q-input>

      <q-btn
        flat
        round
        dense
        :icon="props.inFullscreen ? 'fullscreen_exit' : 'fullscreen'"
        @click="setFs(props)"
      >
        <q-tooltip :disable="$q.platform.is.mobile" v-close-popup>
          {{ props.inFullscreen ? "Exit Fullscreen" : "Toggle Fullscreen" }}</q-tooltip>
      </q-btn>

      <q-btn
        flat
        round
        dense
        :icon="isGrid ? 'list' : 'grid_on'"
        @click="isGrid = !isGrid"
      >
        <q-tooltip :disable="$q.platform.is.mobile" v-close-popup>{{isGrid ? "List" : "Grid"}}</q-tooltip>
      </q-btn>
    </template>
    <template v-if="isGrid" #item="props">
      <div
        class="q-pa-xs col-xs-12 col-sm-6 col-md-4 col-lg-3 grid-style-transition"
        :style="props.selected ? 'transform: scale(1.05);' : ''"
      >
        <q-card :class="props.selected ? 'bg-grey-2' : ''">
          <q-card-section>
            <q-checkbox dense v-model="props.selected" :label="props.row.name"></q-checkbox>
          </q-card-section>
          <q-separator></q-separator>
          <q-list>
            <q-item v-for="col in props.cols.filter(col => col.name !== 'desc')" :key="col.name">
              <q-item-section>
                <q-item-label caption>{{ col.label }}</q-item-label>
                <!-- IF on grid view body-cell-[cellname] is used, this custom slot will be used -->
                <q-item-label v-if="customSlots.some(v=> v.endsWith(col.name))">
                  <slot :name="customSlots.filter(v=> v.endsWith(col.name))[0]" v-bind="props"></slot>
                </q-item-label>
                <!-- ELSE render default forward column classes and styles props -->
                <q-item-label v-else :class="col.classes" :style="col.style">{{ col.value }}</q-item-label>
              </q-item-section>              
            </q-item>
          </q-list>
        </q-card>
      </div>
    </template>
<!--     <template v-if="customSlots.length > 0 && !isGrid">      
      <template v-for="slot in customSlots.map(v => v.split('-')[2])" #[bodySlotName(slot)]="props">
        <slot :name="`for-both-${slot}`" v-bind="props"></slot>
      </template>
    </template> -->
    <!-- forward other slots -->
    <template v-for="(_, slot) of $slots" v-slot:[slot]="scope">
      <slot :name="slot" v-bind="scope || {}"></slot>
    </template>
  </q-table>
</script>
              
            
!

CSS

              
                .grid-style-transition
  transition: transform .28s, background-color .28s
              
            
!

JS

              
                const defaultItem = {
  name: '',
  code: '',
  buyRate: '',
  spotRate: '',
  sellRate: '',
  symbol: '',
  status: ''
}
const statuses = [
  'Active', 'Inactive'
]
const currencyColumns = [
   {
     name: "name",
     align: "left",
     label: "Currency Name",
     field: "name",
     sortable: true
   },
   {
     name: "buyRate",
     align: "center",
     label: "Buy Rate",
     field: "buyRate",
     sortable: true,
     classes: 'text-green'
   },
   {
     name: "sellRate",
     align: "left",
     label: "Sell Rate",
     field: "sellRate",
     sortable: true,
     classes: 'text-red'
   },
   {
     name: "symbol",
     align: "center",
     labelalign: "left",
     label: "Symbol",
     field: "symbol",
     sortable: true
   },
   {
     name: "status",
     align: "center",
     label: "Status",
     field: "status",
     sortable: true
   },
   {
     name: "action",
     align: "center",
     label: "Action",
     field: ""
   }
 ]
const currencies = [
  {
    name: "Malaysian Rinngit",
    code: "MYR",
    buyRate: "4.097(-2.5%)",
    spotRate: "4.19",
    sellRate: "4.238(+0.5%)",
    symbol: "RM",
    status: "Active"
  },
  {
    name: "Singapore Dollar",
    code: "SGD",
    buyRate: "xxxx(-2.5%)",
    spotRate: "x.xx",
    sellRate: "x.xxx(+0.5%)",
    symbol: "$",
    status: "Active"
  },
  {
    name: "Chinese Yuan",
    code: "CNY",
    buyRate: "xxxx(-2.5%)",
    spotRate: "x.xx",
    sellRate: "x.xxx(+0.5%)",
    symbol: "¥",
    status: "Inactive"
  },
  {
    name: "Malaysian Rinngit",
    code: "MYR",
    buyRate: "4.097(-2.5%)",
    spotRate: "4.19",
    sellRate: "4.238(+0.5%)",
    symbol: "RM",
    status: "Active"
  },
  {
    name: "Singapore Dollar",
    code: "SGD",
    buyRate: "xxxx(-2.5%)",
    spotRate: "x.xx",
    sellRate: "x.xxx(+0.5%)",
    symbol: "$",
    status: "Inactive"
  },
  {
    name: "Chinese Yuan",
    code: "CNY",
    buyRate: "xxxx(-2.5%)",
    spotRate: "x.xx",
    sellRate: "x.xxx(+0.5%)",
    symbol: "¥",
    status: "Active"
  }
]
const { ref, computed, reactive, toRefs, onMounted } = Vue
const { useQuasar } = Quasar

const app = Vue.createApp({
  setup () {
    const q$ = useQuasar()
    const fd = reactive({
      grid: false,
      selected: [],
      statusOpts: statuses,
      inFs: false,
      columns: [
        {
          name: 'name',
          required: true,
          label: 'Dessert (100g serving)',
          align: 'left',
          field: row => row.name,
          format: val => `${val}`,
          sortable: true
        },
        { name: 'calcium', label: 'Calcium (%)', field: 'calcium', sortable: true, sort: (a, b) => parseInt(a, 10) - parseInt(b, 10) },
        { name: 'iron', label: 'Iron (%)', field: 'iron', sortable: true, sort: (a, b) => parseInt(a, 10) - parseInt(b, 10) },
        { name: 'actions', label: 'Actions', field: '', align:'center' },
      ],
      data: [
        {
          name: 'Frozen Yogurt',
          calories: 159,
          fat: 6.0,
          carbs: 24,
          protein: 4.0,
          sodium: 87,
          calcium: '14%',
          iron: '1%'
        },
        {
          name: 'Ice cream sandwich',
          calories: 237,
          fat: 9.0,
          carbs: 37,
          protein: 4.3,
          sodium: 129,
          calcium: '8%',
          iron: '1%'
        },
        {
          name: 'Eclair',
          calories: 262,
          fat: 16.0,
          carbs: 23,
          protein: 6.0,
          sodium: 337,
          calcium: '6%',
          iron: '7%'
        },
        {
          name: 'Cupcake',
          calories: 305,
          fat: 3.7,
          carbs: 67,
          protein: 4.3,
          sodium: 413,
          calcium: '3%',
          iron: '8%'
        },
        {
          name: 'Gingerbread',
          calories: 356,
          fat: 16.0,
          carbs: 49,
          protein: 3.9,
          sodium: 327,
          calcium: '7%',
          iron: '16%'
        },
        {
          name: 'Jelly bean',
          calories: 375,
          fat: 0.0,
          carbs: 94,
          protein: 0.0,
          sodium: 50,
          calcium: '0%',
          iron: '0%'
        },
        {
          name: 'Lollipop',
          calories: 392,
          fat: 0.2,
          carbs: 98,
          protein: 0,
          sodium: 38,
          calcium: '0%',
          iron: '2%'
        },
        {
          name: 'Honeycomb',
          calories: 408,
          fat: 3.2,
          carbs: 87,
          protein: 6.5,
          sodium: 562,
          calcium: '0%',
          iron: '45%'
        },
        {
          name: 'Donut',
          calories: 452,
          fat: 25.0,
          carbs: 51,
          protein: 4.9,
          sodium: 326,
          calcium: '2%',
          iron: '22%'
        },
        {
          name: 'KitKat',
          calories: 518,
          fat: 26.0,
          carbs: 65,
          protein: 7,
          sodium: 54,
          calcium: '12%',
          iron: '6%'
        }
      ],
      noti: () => {},
      show_dialog: false,
      editedIndex: -1,
      editedItem: defaultItem,
      filter: '',
      currencyColumns: currencyColumns,
      currencyData: currencies,
      pagination: {
        page: 1,
      },
      page: 1,
      totalRecord: 0,
      pageCount: 1,
    })
    
    function editRow(props) {
      fd.noti()
      // do something
      fd.noti = q$.notify({
        type: 'info',
        textColor: 'grey-10',
        multiLine: true,
        message: `I'll edit row data => ${JSON.stringify(props.row).split(',').join(', ')}`,
        timeout: 2000
      })
    }
    
    function editRow(props) {
      fd.noti()
      // do something
      fd.noti = q$.notify({
        type: 'info',
        textColor: 'grey-10',
        multiLine: true,
        message: `I'll edit row data => ${JSON.stringify(props.row).split(',').join(', ')}`,
        timeout: 2000
      })
    }
    
    function deleteRow(props){
      fd.noti()
      // do something
      fd.noti = q$.notify({
        type: 'negative',
        multiline: true,
        message: `I'll delete row data => ${JSON.stringify(props.row).split(',').join(', ')}`,
        timeout: 2000
      })
    }
    
    function addRow() {
      if (fd.editedIndex > -1) {
        Object.assign(fd.currencyData[fd.editedIndex], fd.editedItem);
      } else {
        fd.currencyData.push(fd.editedItem);
      }
      fd.close()
    }
    
    function deleteItem(item) {
      const index = fd.currencyData.indexOf(item);
      confirm("Are you sure you want to delete this item?") &&
        fd.currencyData.splice(index, 1);
    }
    
    function editItem(item) {
      fd.editedIndex = fd.currencyData.findIndex((v, i) =>v.__index === item.__index)
      fd.editedItem = Object.assign({}, item);
      fd.show_dialog = true;
    }
    
    function close () {
      fd.show_dialog = false
      setTimeout(() => {
        fd.editedItem = defaultItem
        fd.editedIndex = -1
      }, 300)
    }
    
    function setFs(props){
      props.toggleFullscreen()
      fd.inFs = props.inFullscreen
    }
    
    function updateRow() {
      fd.currencyData.splice(fd.editedIndex, 1, fd.editedItem)
      q$.notify({type:"positive", message: `Item '${fd.editedItem.name}' updated.`, timeout: 500 })
    }
    
    onMounted(() => {
      // add indices
      fd.currencyData = fd.currencyData.map((v, i) => ({ ...v, __index: i}))
    })
    
    return {
      ...toRefs(fd),
      editRow,
      editRow,
      deleteRow,
      addRow,
      deleteItem,
      editItem,
      close,
      setFs,
      updateRow,
    }
  },
  
})

// QTable Wrapper component definition
app.component('table-wrapper', {
  template: '#table-wrapper',
  emits: ['update:filter', 'grid'],  
  // props: { you could pass QTable props here, otherwise they are in attrs object and will fall through the wrapped QTable }
  setup(props, { attrs, slots, emit }){
    // get custom slots
    const customSlots = Object.keys(slots).filter(v => {
      if (v.startsWith('grid-item-') || v.startsWith('for-both-') || v.startsWith('body-cell-')) {
        return true
      }
    })
    
    const filter = computed({
      get: _ => attrs?.filter,
      set: v => { emit('update:filter', v) }
    })
    
    const isGrid = computed({
      get: _ => attrs?.grid,
      set: v => { emit('update:grid', v) }
    })
    
    return {
      setFs(props){
        props.toggleFullscreen()
      },
      isGrid,
      filter,
      customSlots,
      bodySlotName(name){
        return 'body-cell-' + name
      }
    }
  }
})

app.use(Quasar, { config: {} });
app.mount("#q-app");
              
            
!
999px

Console