mongo-datatables

A Python library that wires DataTables to MongoDB — server-side processing, search, filtering, and full CRUD via the Editor extension. This site is a live demo.

pip install mongo-datatables
ArtistTitleLabel YearGenreFormatRating
How It Works
Client — DataTables Config

serverSide: true tells DataTables to delegate pagination, sorting, and search to the server via Ajax POST. scroller replaces traditional pagination with virtual scrolling — only visible rows are rendered in the DOM. select: true enables row selection. buttons adds Copy/Excel/PDF/Print export.

new DataTable('#table', {
  serverSide: true,
  ajax: { url: '/api/records', type: 'POST' },
  scroller: { rowHeight: 46 },
  scrollY: '39vh',
  select: true,
  buttons: ['copy', 'excel', 'pdf', 'print']
});
Server — mongo-datatables

DataTables(db, 'records', data, data_fields) translates the Ajax request into a MongoDB aggregation pipeline. get_rows() returns { draw, recordsTotal, recordsFiltered, data } — the standard server-side response. The library handles $skip, $limit, $sort, and $match automatically.

@app.route('/api/records', methods=['POST'])
def records_data():
    data = request.get_json()
    dt = DataTables(db, 'records', data,
                    data_fields=FIELDS)
    return jsonify(dt.get_rows())