SQLAlchemy integration of jQuery DataTables
Project description
sqlalchemy-datatables is a framework agnostic library providing an SQLAlchemy integration of jQuery DataTables >= 1.10, and helping you manage server side requests in your application.
Installation
To install via pip:
Python 2
$ pip install sqlalchemy-datatables
Python 3
$ pip3 install sqlalchemy-datatables
To install from source:
$ git clone git@github.com:Pegase745/sqlalchemy-datatables.git
$ cd sqlalchemy-datatables
$ pip install .
To contribute:
In a virtualenv
$ git clone git@github.com:Pegase745/sqlalchemy-datatables.git
$ cd sqlalchemy-datatables
$ make all
Usage
@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()
Examples
You can find working examples in the repository, including an integration with the yadcf plugin:
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
Close
Hashes for sqlalchemy-datatables-2.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6354aa992509c9aefe2846700bb0ad45060d723c6f3dd00e516b422c31e480d2 |
|
MD5 | 5db1be3ee04de56cd698692b30192a2b |
|
BLAKE2b-256 | 8fced4553753d7558a09a4553ff04cd18a5bf2e68cad05cd3cc21d05eabc81e7 |