javascript - Send jquery array to controller for processing in Symfony2 -
i'm trying send array of row id's controller in order batch update, think did array part (i'm not @ jquery, still learning) have no idea how send controller array contains ids of rows update.
here's twig:
{% block javascripts %} <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> $(document).ready(function () { $('#selectall').click(function () { $('.selectedid').prop('checked', ischecked('selectall')); }); }); function ischecked(checkboxid) { var id = '#' + checkboxid; return $(id).is(":checked"); } function resetselectall(id) { // if checkbox selected, check selectall checkbox // , viceversa if ($(".selectedid").length == $(".selectedid:checked").length) { $("#selectall").attr("checked", "checked"); var ids = []; ids.concat(id); } else { $("#selectall").removeattr("checked"); removeitem = id; ids = jquery.grep(arr, function(value) { return value != removeitem; }); } if ($(".selectedid:checked").length > 0) { $('#edit').attr("disabled", false); } else { $('#edit').attr("disabled", true); } } </script> {% endblock %} {% block body %} <table> <thead> <tr> <th><input type="checkbox" id="selectall"></th> <th>{{ 'general.date'|trans }}</th> <th>{{ 'general.order_number'|trans }}</th> <th>{{ 'general.description'|trans }}</th> <th>{{ 'general.company_name'|trans }}</th> <th>{{ 'general.name'|trans }}</th> <th>{{ 'form.status'|trans }}</th> <th>winpoints</th> </tr> </thead> {% details in details %} <tbody> <tr> <td><div align="center"><input type="checkbox" class="selectedid" name="selectedid" onclick="resetselectall({{details.id}});" /></div></td> <td>{{ details.date | date("m/d/y") }}</td> <td>{{ details.order_number }}</td> <td>{{ details.description }}</td> <td>{{ details.company }}</td> <td>{{ details.name }}</td> <td>{{ details.status }}</td> <td>{{ details.winpoints }}</td> </tr> </tbody> {% endfor %} </table> <form action="{{ path('advd_group_batch_p_r_status') }}" method="post" {{ form_enctype(formbase) }}> {{ form_widget(form) }} <input class="input_button" type="submit" value="procesar" /> </form> {% endblock %}
any ideas? plus, if see mistakes on jquery code, please let me know i'm doing wrong, haven't been able test because don't know how send array controller.
thank may offer me.
{% block javascripts %} <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> $(document).ready(function () { $('#selectall').click(function () { $('.selectedid').prop('checked', ischecked('selectall')); }); }); function ischecked(checkboxid) { var id = '#' + checkboxid; return $(id).is(":checked"); } function resetselectall(id) { // if checkbox selected, check selectall checkbox // , viceversa if ($(".selectedid").length == $(".selectedid:checked").length) { $("#selectall").attr("checked", "checked"); var ids = []; ids.concat(id); } else { $("#selectall").removeattr("checked"); removeitem = id; ids = jquery.grep(arr, function(value) { return value != removeitem; }); } if ($(".selectedid:checked").length > 0) { $('#edit').attr("disabled", false); } else { $('#edit').attr("disabled", true); } } $(function(){ $('.input_button').click(function(){ $.ajax({ url:"advd_group_batch_p_r_status", datatype:'json', type:'post', data:$("#formc").serialize() }); }); }); </script> {% endblock %} {% block body %} <form action="{{ path('advd_group_batch_p_r_status') }}" method="post" {{ form_enctype(formbase) }} id="formc"> <table> <thead> <tr> <th><input type="checkbox" id="selectall"></th> <th>{{ 'general.date'|trans }}</th> <th>{{ 'general.order_number'|trans }}</th> <th>{{ 'general.description'|trans }}</th> <th>{{ 'general.company_name'|trans }}</th> <th>{{ 'general.name'|trans }}</th> <th>{{ 'form.status'|trans }}</th> <th>winpoints</th> </tr> </thead> {% details in details %} <tbody> <tr> <td><div align="center"><input type="checkbox" class="selectedid" name="selectedid" onclick="resetselectall({{details.id}});" /></div></td> <td>{{ details.date | date("m/d/y") }}</td> <td>{{ details.order_number }}</td> <td>{{ details.description }}</td> <td>{{ details.company }}</td> <td>{{ details.name }}</td> <td>{{ details.status }}</td> <td>{{ details.winpoints }}</td> </tr> </tbody> {% endfor %} </table> {{ form_widget(form) }} <input class="input_button" type="submit" value="procesar" /> </form> </div> </div> </div> </div> </div> {% endblock %}
Comments
Post a Comment