Giter Site home page Giter Site logo

baitcenter / f7-table Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kevinqqnj/f7-table

0.0 0.0 0.0 100 KB

component of Framework7 table for Vue.js, including Pagination, Sorting, Selection, customized cell action

Home Page: https://ourbits.herokuapp.com/f7-table

License: MIT License

JavaScript 47.34% HTML 2.68% Vue 49.97%

f7-table's Introduction

f7-table Component

component of Framework7 table for Vue.js, including Pagination, Sorting, Selection, customized cell action

Snap-shot:

basic

checkbox

cell

Live demo: https://ourbits.herokuapp.com/f7-table

Features

  • One line to create table:
<template>
  <f7-table :fields="fields" :querydata="querydata"">
  </f7-table>
</template>  
  • Pagination
  • Sortable
  • Selectable
  • slot: "data-table-header-selected"
  • slot: "tr", "tr_index" for rows

How to run demo

That's it!

Usage

  1. setup your framework7 (v2) + vue project. Here's one template: https://github.com/kevinqqnj/Framework7-Vue-Webpack-Template-v2
  2. copy src/components/f7-table.vue to your project
  3. import it as component in .vue script. e.g.
<script>
export default {
    components: {
        "f7-table": require('../components/f7-table.vue'),
    },
    ...
  1. For startup, you only need to specify :fields & :querydata props for f7-table component in .vue template.
# /src/pages/basic-table.vue
<template>
<f7-table :fields="fields" :querydata="querydata">
    <!-- slot: data-table-header-selected -->
    <!-- thead -->
    <!-- tbody -->
    <!-- slot: rows -->
</f7-table>
</template>

Advanced

Props:

  1. ":fields" format:
fields: [
              {
                    name: 'name',	// field name, must Unique
                    title: 'Dessert (100g serving)',
                    titleClass: 'label-cell',
                    dataClass: 'numeric-cell',
                    sortTable: 'Ob',	// sortable or not?
                },
		...
	],
  1. ":querydata" format: See: https://github.com/kevinqqnj/f7-table#fetch-data-from-server

  2. Show checkbox at first column:

# /src/pages/checkbox-table.vue
<f7-table :__checkbox="true" />
  1. use your own sortOrders data:
<f7-table :sortOrders.sync="sortOrders" />
  1. use your own per_page data:
<f7-table :per_page.sync="per_page" />

Events:

  1. @pageChange: listen to page-change event, then fetch new data from server
<f7-table @pageChange="query_data_from_api()" />
  1. @orderChange: listen to sort-order-change event, then fetch new data from server
<f7-table @orderChange="query_data_from_api()" />

Slot

  1. slot: "data-table-header-selected" You can define your own information & actions shown in "data-table-header-selected". e.g.
  <div slot="data-table-header-selected" class="data-table-header-selected">
    <div class="data-table-title-selected">
                    Selected <f7-badge color="blue">{{selectedIndexList.length}}</f7-badge> Desserts, 
                    <f7-badge color="blue">{{selected_calories_sum.toFixed(1)}}</f7-badge> Calories
    </div>
  </div>

  1. slot: "tr", "tr_index" for rows You can easily define your actions on different cells, e.g. open "Edit" popover, link to other page, etc. e.g.:
# /src/pages/cell-action-table.vue
<f7-table :fields="fields" :querydata="querydata" :__checkbox="true" :sortOrders.sync="sortOrders" :per_page.sync="per_page" @orderChange="query_data_from_api()" @pageChange="query_data_from_api()">
    <!-- thead -->
    <!-- tbody -->
    <tr slot="rows" slot-scope="props">
                <td class="checkbox-cell">
                    <label class="checkbox"><input type="checkbox" :value="props.tr_index" v-model="selectedIndexList"><i class="icon-checkbox"></i></label>
                </td>
                <td v-for="f in fields" @click="cell_clicked(props.tr_index, f.name, props.tr[f.name])">
                    {{ props.tr[f.name] }}
                </td>
                <!-- if you need different CSS/Actions for different columns, not use "td v-for", just render "td" one by one-->
    </tr>

</f7-table>

fetch data from Server

The table shows data from 'querydata', it can be fetched from server side, format is like:

# /src/querydata.js
{
  "data": [
          {
            name: 'Frozen Yogurt',
            calories: 159,
            fat: 6.0,
            carbs: 24,
            protein: 4.0,
            sodium: 87,
            calcium: '14%',
            iron: '1%'
          },
 	...
        ], 
  "current_page": 1, 
  "from": 1, 
  "last_page": 12, 
  "per_page": 10, 
  "to": 10, 
  "total": 245
}

f7-table's People

Contributors

kevinqqnj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.