Pegase745 / sqlalchemy-datatables

SQLAlchemy integration of jQuery DataTables >= 1.10.x (Pyramid and Flask examples)
MIT License
159 stars 67 forks source link

INVALID JSON using sqlalchemy Datatable #44

Closed kouroshh closed 7 years ago

kouroshh commented 8 years ago

I am using the same template and example which exists in sqlalchemy Datatable sample in: http://sqlalchemy-datatables.readthedocs.org/en/latest/ my code is the following, my problem is invalid json, that I could not find any problems in it. any helps? The output of rowTable.output_result() is:

{'aaData': [{'1': 'DOC - 1457715381', '0': '60352794'}, {'1': 'DOC - 1457715381', '0': '2768077336'}, {'1': 'DOC - 1457715381', '0': '6247239243'}, {'1': 'DOC - 1457715381', '0': '8257884017'}, {'1': 'DOC - 1457715381', '0': '8508822379'}], 'iTotalRecords': '5', 'sEcho': '1', 'iTotalDisplayRecords': '5'}

ERROR: DataTables warning: table id=mytable - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

in HTML Script tag: $(document).ready(function(){ $('#mytable').dataTable({ "bProcessing": true, "bServerSide": true, "sAjaxSource": "${request.route_path('doclist')}" });

MAKO: @view_config(route_name='doclist', request_method='GET', renderer='service:/templates/partials/doclist.mako', permission = 'login') def viewListDocuments(self): r = self.r creator_id = 18 columns = [] columns.append(ColumnDT('doccode')) columns.append(ColumnDT('doctitle')) query = DBSession.query(Document).filter(Document.creator_id == creator_id) rowTable = DataTables(r.GET, Document, query, columns) return rowTable.output_result()

Pegase745 commented 8 years ago

JSON requires double quotes for its strings.

{
    "aaData": [{
        "1": "DOC - 1457715381",
        "0": "60352794"
    }, {
        "1": "DOC - 1457715381",
        "0": "2768077336"
    }, {
        "1": "DOC - 1457715381",
        "0": "6247239243"
    }, {
        "1": "DOC - 1457715381",
        "0": "8257884017"
    }, {
        "1": "DOC - 1457715381",
        "0": "8508822379"
    }],
    "iTotalRecords": "5",
    "sEcho": "1",
    "iTotalDisplayRecords": "5"
}

So I just tried my repo example and I don't seem to have the problem. Don't know what can cause this at the moment, but if it really don't work out try json.dumps of the output result.

kouroshh commented 8 years ago

not working!

Pegase745 commented 8 years ago

Try forking and pushing your example for me to test it please On Mar 29, 2016 2:27 PM, "kourosh" notifications@github.com wrote:

not working!

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/Pegase745/sqlalchemy-datatables/issues/44#issuecomment-202868953