SQLAlchemy integration of jQuery DataTables
Project description
sqlalchemy-datatables is a library providing an SQLAlchemy integration of jQuery DataTables. It helps you manage server side requests in your application.
It is framework agnostic, tested with Pyramid and Flask mainly.
It only depends on SQLAlchemy, and is compatible with version 1.10.x of DataTables.
Installation
To install the stable version:
pip install sqlalchemy-datatables
Usage
views.py
@view_config(route_name='data', renderer='json')
def data(request):
"""Return server side data."""
# defining columns
# - explicitly cast date to string, so string searching the date
# will search a date formatted equal to how it is presented
# in the table
columns = [
ColumnDT(User.id),
ColumnDT(User.name),
ColumnDT(Address.description),
ColumnDT(func.strftime('%d-%m-%Y', User.birthday)),
ColumnDT(User.age)
]
# defining the initial query depending on your purpose
# - don't include any columns
# - if you need a join, also include a 'select_from'
query = DBSession.query().\
select_from(User).\
join(Address).\
filter(Address.id > 4)
# instantiating a DataTable for the query and table needed
rowTable = DataTables(request.GET, query, columns)
# returns what is needed by DataTable
return rowTable.output_result()
You can find detailed a working example for Pyramid in the repository, including per column search, and one with the yadcf plugin. Currently the Flask example is not working
Pyramid example:
# go to directory
cd sqlalchemy-datatables/examples/pyramid_tut
# install example app
pip install -e .
# initialize the database
initialize_pyramid_tut_db development.ini
# start server
pserve development.ini
# browse to localhost:6543
Documentation
The latest documentation is available online on Read the Docs.
Changelog
All notable changes to this project will be documented in this section.
This project adheres to Semantic Versioning and Keep A Changelog.
License
The project is licensed under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for sqlalchemy-datatables-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccc7a4abd93af093c4b12d2f5307301f7b3504458b976a3d74b19cadcac3b03e |
|
MD5 | 7dd8fa9becf6924284117817c6cff7dd |
|
BLAKE2b-256 | bd672fcfb8e70d7a32a7029a4906d59b15ee212e709452a9fa87531d9895f056 |