Example of Multi Select Datatable Within a Form, passing selected values to Servlet on Submit

Example of Multi Select Datatable Within a Form, passing selected values to Servlet on Submit

ggiavelliggiavelli Posts: 5Questions: 3Answers: 0

Hi,

I have a working multi-select datatable. How can I use it in a form with a submit button, calling a java servlet with the data values from a particular column (say col 0). Do I have to get into jQuery and maintain an array of selections or should be an API call to get the data for submit. Can some one show a simple example?

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @ggiavelli ,

    Are you expecting to pass the column values with Ajax? If so, use ajax.data to pass the values. And to get the values, use rows({selected:true}).data().pluck(0).

    Cheers,

    Colin

  • ggiavelliggiavelli Posts: 5Questions: 3Answers: 0
    edited November 2018

    I am getting all the datatable values and some formatting info. Is there a way to clean this up on the client side so I only get the first columns values?

    e.g.
    $('button').click( function() {

                var data = table.rows( ['.selected'] ).data().pluck(0);
                var stringdata = JSON.stringify(data);
                alert(
                    "The following data is selected: \n\n"+
                    stringdata
                );
                return false;
            } );
    
  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    The pluck() API can get column 0 using pluck(0) of using arrays. However if you are using columns.data then use the object property as shown in the docs.

    Kevin

This discussion has been closed.