Coder Social home page Coder Social logo

flaskdatatables's Introduction

FlaskDataTables

A straight-forward datatables integration for flask

Installation

Simply copy datatables.py to your flask project and import it.

Usage

The module consists of two classes. One is Collection which is responsible for converting your data to JSON string, and DataTables which is responsible for rendering the Datatable HTML and Javascript.

app.py

from flask import Flask, Response, render_template
from modules.datatables import Collections, DataTables
app = Flask(__name__)

# This is where we render the table
@app.route("/")
def index():
    dataTables = DataTables(source="/data")
    dataTables.setColumns([{"param":"Parameters"},{"val":"Value"}])
    return render_template('index.html', table=dataTables.render())

# This is where we create the JSON for our response to DataTable's AJAX Request
@app.route("/data")
def data():
    list = [
        {'param': 'foo', 'val': 2},
        {'param': 'bar', 'val': 10}
    ]
    collection = Collections(list)
    return Response(collection.respond(), mimetype="application/json")

if __name__ == "__main__":
    app.run(debug=True)

templates/index.html

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <!-- MAKE SURE YOU CHANGE THE JS AND CSS URLS -->
    <link rel="stylesheet" href="dataTables.min.css">
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="jquery.dataTables.min.js"></script>
</head>
<body>
{{ table|safe }}
</body>
</html>

##TODO

fix incoming bugs code documentaion Features Ability To Add Action Buttons (THE CRUD BUTTONS)

flaskdatatables's People

Contributors

johndavedecano avatar

Watchers

 avatar  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.