<div dir="ltr">Hi -<div><br></div><div>I've googled around a bit and am having trouble figuring out how to pass a value from a flask page back to the view method that produces the json for loading a datatables table.</div><div><br></div><div>Currently I'm using datatables to display all the entries in a given table with great success:</div><div><br></div><div>in an html template where I have table with id="test_table":</div><div><div><font face="monospace, monospace"><script></font></div><div><font face="monospace, monospace">        $(document).ready(function() { $('#test_table').DataTable( { "ajax" : $SCRIPT_ROOT + "/_get-test-rows" } ); } );</font></div><div><font face="monospace, monospace">    </script></font></div><div><br></div><div>in views.py:</div><div><br></div><div><font face="monospace, monospace">@main.route('/_get-test-rows')</font></div><div><font face="monospace, monospace">def get_test_rows():</font></div><div><font face="monospace, monospace">    trows = Test.query.order_by(Test.name)</font></div><div><font face="monospace, monospace">    rows = [ [<a href="http://tr.name">tr.name</a>, <a href="http://tr.x.name">tr.x.name</a>, tr.y, tr.z] for tr in trows]</font></div><div><font face="monospace, monospace">    return josnify(data = rows)</font></div><div>    </div><div><div class="gmail_signature"><div dir="ltr"><div><br></div><div>In my above example, I have another table X that tr.x points to. I'd like to have a page that displays information about individual rows in X that has a table showing all rows from Test that have that point to that particular row in X.</div><div><br></div><div><font face="monospace, monospace">@main.route('/show-x/<int:id>')</font></div><div><font face="monospace, monospace">def show_x(id):</font></div><div><font face="monospace, monospace">    x = X.query.get_or_404(id)</font></div><div><font face="monospace, monospace">    return render_template('x.html', x = x)</font></div><div><br></div><div>I know I can just get all the Test rows I need with tr = Test.query.filter_by(x_id = id).order_by(Test.name) pass them to render_template and render the table myself, but I'd prefer to have a jQuery call in the page that gets the rows of Test where x_id = <a href="http://x.id">x.id</a>. Sometimes there are many rows of Test that will be shown and I'd like the page to start loading so the User sees that the click did get through and now we're waiting for the values to get loaded.</div><div><br></div><div>My problem is that I can't figure out how to write the <script> call to include <a href="http://x.id">x.id</a> and how to read that value in my view function. I tried this:</div><div><br></div><div><div><font face="monospace, monospace">$(document).ready(function() { $('#test_table').DataTable( { "ajax" : { "url" : $SCRIPT_ROOT + "/_get-x-test-rows", </font><span style="font-family:monospace,monospace">"data" : { "id" : {{ <a href="http://x.id">x.id</a> }} }} ); } );</span></div></div><div><br></div><div>and</div><div><br></div><div><div><font face="monospace, monospace">@main.route('/_get-x-test-rows/<int:id>')</font></div><div><font face="monospace, monospace">def get_x_test_rows(id):</font></div><div><font face="monospace, monospace">    tr = Test.query.filter_by(x_id = id).order_by(Test.name)</font></div><div><font face="monospace, monospace">    ...</font></div></div><div><br></div><div>But the view method never gets called. I think I probably need to do something along the lines of</div><div><br></div><div><font face="monospace, monospace">@main.route('/_get-x-test-rows')</font></div><div><font face="monospace, monospace">def get_x_test_rows()</font></div><div><font face="monospace, monospace">    id = extract the id value from something somehow</font></div><div><font face="monospace, monospace">    tr = Test.query.filter_by(x_id = id).order_by(Test.name)</font></div><div><font face="monospace, monospace">    ...</font></div><div><br></div><div>But I haven't been able to figure out how to do that.</div><div><br></div><div>Could someone point me in the right direction to figure out how to do this?</div><div><br></div><div>Thanks,</div><div>- Craig</div></div></div></div>
</div></div>