Skip to main content


Project description

mongoengine datatables

A script for using the jQuery plug-in DataTables server-side processing with MongoEngine.

Works with Flask and Django. Supports column sorting and filtering by multiple search terms. Supports ReferenceFields & EmbeddedDocumentField for search.



You can install with pip:

pip install mongoengine_datatables

Minimal example mongoengine datatables

Copy paste this code to

from flask import Flask, render_template_string, jsonify, request
from flask_mongoengine import MongoEngine
from mongoengine_datatables import DataTables
app = Flask(__name__)
db = MongoEngine(app)

class Hello(db.Document):
    field_one = db.StringField()
    field_two = db.StringField()

@app.route('/api/', methods=['POST'])
def api():
    args = request.get_json()
    res = DataTables(Hello, args).get_rows()
    return jsonify(res)

def hello_world():
    if not Hello.objects(field_one='Hello').first():
        Hello(field_one='Hello', field_two='World').save()
    return render_template_string(
    <html> <head>
        <link rel="stylesheet" type="text/css"
    <body class="p-3">
          <table id="dt_table" class="table table-striped" style="width:100%">
    <script type="text/javascript"
        $(function () {
                serverSide: true,
                ajax: {
                    url: '{{ url_for('api') }}',
                    dataSrc: 'data',
                    type: 'POST',
                    contentType: 'application/json',
                    data: function (d) {
                        return  JSON.stringify(d)
                columns: [
                    {data: 'field_one'},
                    {data: 'field_two'},
    </script> </html>

if __name__ == "__main__":, host='')

Install modules & run:



Advanced usage:

embed_search - For specific search in EmbeddedDocumentField q_obj - Additional search results in reference collection custom_filter - Your custom filter

DataTables(your_model, request_args, embed_search={}, q_obj=[], custom_filter={})

For datetime field

DataTables return datetime as epoch time with milliseconds. Example:

{'my_date': {'$date': 1605116909954}}

You can convert it:

import time
time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(1605116909954/1000.0))

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mongoengine_datatables, version 0.0.7
Filename, size File type Python version Upload date Hashes
Filename, size mongoengine_datatables-0.0.7-py3-none-any.whl (5.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size mongoengine_datatables-0.0.7.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page