In the following code i am trying to add an dropdown box to a tag. To do this i call a function onready and then add it.I have two issues here
1.The table has more than two thousand rows and there i use django pagination.But on ready the drop down box is populated for all the two thousand rows.How can i load the drop down box for the 100 rows i.e, is being paginated.So that it will be faster. 2.Also the drop down box are slower to show data to select.How can i rectify this.
Hope i am clear with the question
{% extends "base/admin_base.html" %}
{% load pagination_tags %}
{% block content %}
<script>
$(document).ready(function() {
$('font').css({'color':'red'})
getcategory('1');
});
function getcategory(flag)
{
if($("#cgroup").val().trim() == "-1")
{
alertmsg+= "Select Category group\n"
}
else
{
var html = "";
var opt = "";
var cgroup = $("#cgroup").val();
html += '<select id="category" class="category">';
html += '<option value="-1" class="cat">Select Category</option>';
{% for category in response_dict.category %}
gp = '{{category.categorygroup.id}}' ;
if(cgroup == gp)
{
html += '<option class="data" value="{{category.id}}">{{category.name}}</option>';
}
{% endfor %}
html += '</select>';
if(flag == 1)
{
$(".tg").html('');
$(".tg").append(html);
}
}
}
</script>
<h1>Tag data</h1>
{% autopaginate response_dict.taggeddata 100 %}
<div align="right">{% paginate %}</div>
<form action="/users/saveuser/" method="post">{% csrf_token %}
<table>
<tr><td><font>*</font>Select Category group for tagging</td><td>
<select id="cgroup" onchange="getcategory('1');">
{% for group in response_dict.categorygroup %}
<option value="{{group.id}}">{{group.name}}</option>
{% endfor %}
</select>
</td></tr>
</table>
<b>
<table>
<tr><td><font>*</font>Select Category group for tagging</td><td>
<select id="cgroup" onchange="getcategory('1');">
{% for group in response_dict.categorygroup %}
<option value="{{group.id}}">{{group.name}}</option>
{% endfor %}
</select>
</td></tr>
</table>
</b>
<table id="box-table-a">
<colgroup>
<col class="vzebra-odd">
</colgroup>
<thead>
<tr><th id="vzebra-comedy" scope="col">Field1</th><th id="vzebra-adventure" scope="col">Field2</th><th id="vzebra-comedy" scope="col">Field3</th><th id="vzebra-adventure" scope="col">Field4</th><th id="vzebra-comedy" scope="col">Field5</th><th id="vzebra-adventure" scope="col">Field6</th><th id="vzebra-comedy" scope="col">Tag</th><th id="vzebra-adventure" scope="col">Actions</th><thead></tr>
<tbody>
{% for td in response_dict.taggeddata %}
<tr id="{{td.id}}">
<td class="tg">Select category</td>
</tr>
{% endfor %}
</tbody>
</table>
<input type="button" value="Add" id="addbtn" onclick="validate();"/>
</form>
{% endblock %}