0

I have a Jquery DataTable with multiselect ability. Moreover there is a button and a div element:

    <script>
            $(document).ready(function() {
                        var tablemovChAf  = $('#movChAf').DataTable({

                        //multiselect       
                        $('#movChAf tbody').on('click', 'tr', function () { 
                                $(this).toggleClass('selected');            
                        } );

            })
    </script>

    <button name="sbmsimulate" class="button-input btn btn-info" id="sbmsimulate" style="info" type="button" >
    <div id="divAccMovement"></div>

What I want is to send all the selected rows to "accMovement.jsp" by clicking on the button.

$('#sbmsimulate').click( function () {

    $('#divAccMovement').load('accMovement.jsp',{
        mode:"2",
        arrayData:tablemovChAf.rows('.selected').data()
    });

} );    

my jsp accMovement.jsp looks like this;

<%
String str_mode=request.getParameter("mode").toString();
String[] arrayData=null;

if (str_mode.equals("2")) {
    arrayData=request.getParameterValues("arrayData[]");
}

%>

I tried the solution of : Passing javascript array to servlet (In fact, that is what I have done) but it didnt work for me. Nothing happens when I click the button.

I was debugging, and it seems the problem is with:

arrayData:tablemovChAf.rows('.selected').data()

because, if it is commented (and the "if" statement in the jsp is commented also) it is working. However what I need is to send the selected rows to the jsp page.

What is the correct way to send the array from the client and receive the array on the server?

Thanks in advance.

Community
  • 1
  • 1
Lev
  • 693
  • 1
  • 8
  • 24

1 Answers1

0

I found a solution not so smart for my case (following this jQuery DataTables Getting selected row values), it does not exactly what I need, but I can add some statements later in order to achive my goal

    $('#sbmsimulate').click( function () {

        var ids = $.map(tablemovChAf.rows('.selected').data(), function (item) {
            return item[11]
        });

        $('#divAccMovement').load('accMovement.jsp',{
            mode:"2",
            arrayData:ids
            });
    } );

The column of index 11 is the id of my dataTable, so in the server side I can get all the information about every row.

However I would like to avoid that step:

    var ids = $.map(tablemovChAf.rows('.selected').data(), function (item) {
        return item[11]
    });

and specify everything in the parameter, something like this :

arrayData:tablemovChAf.rows('.selected').data()
Community
  • 1
  • 1
Lev
  • 693
  • 1
  • 8
  • 24