[Answer]-Pass variable to Javascript file

1๐Ÿ‘

โœ…

2 easy ways are:

  1. You could have django render your javascript

  2. you could set a global JS config variable in your django template and then your JS file could look for the variable.

in django template

<script type="text/javascript">
var CONFIG = {};
CONFIG.GRID_NAME = "{{ your name }}";
</script>

THen in your js file

you can check to make sure that CONFIG.GRID_NAME is set and use it appropriately.

๐Ÿ‘คdm03514

0๐Ÿ‘

Assuming you have a container div

<div id="jq-grid-container" data-my-column="{{ variable here }}"></div>

Then where you set up your jQGrid, you can just fetch your variable name with

var myColumn = $('#jq-grid-container').data('my-column');

Leave a comment