Search code examples
bootstrap-table

queryParams bootstrap table


I'm creating my table inside a div like this:

var tabla = $('<table id="tablaConteo2"></table>');
var thead = $('<thead></thead>');
var enc = $('<tr> <th></th> <th></th> <th></th> <th></th> <th></th> </tr>');
thead.appendTo(tabla);
enc.appendTo(thead);
tabla.appendTo('#tablaDatosToma2');
var $tabla = $('#tablaConteo2');

and then I'm using this library to initialize the table like this:

$tabla.bootstrapTable({
                    height: 200,
                    url: 'BuscarCodigo',
                    method: 'post',
                    queryParams: function(p){
                    return{
                        codigoProducto : $('#codigoToma2').val(),
                        bodegaID: $('#bodega').val()
                    };

                },
                pagination: true,
                pageSize: 50,
                pageList: [10, 25, 50, 100, 200],
                showRefresh: true,
            columns: [
            {
                field: 'codigoProducto',
                title: 'C\u00F3digo'
            }, 
            {
                field: 'cantidad',
                title: 'Cant. Actual',
                width: '200px'
            },
            {
                field: 'nuevaCantidad',
                title: 'Cantidad'
            },
            {
                field: 'bodega',
                title: 'Bodega'
            },
            {
                field: 'estanteria',
                title: 'Estanter\u00EDa'
            },
            {
                field: 'seccion',
                title: 'Secci\u00F3n'
            },
            {
                field: 'estanteriaID',
                title: 'Estanter\u00EDa'
            },
            {
                field: 'seccionID',
                title: 'Secci\u00F3n'
            }
            ]
            });

On my servlet I'm getting the parameters as I usually do, like this:

request.getSession().setAttribute("codigoProducto", request.getParameter("codigoProducto"));
request.getSession().setAttribute("bodegaID", request.getParameter("bodegaID"));

The servlet is being executed, but when I try to use the parameters they are null, can anyone help to find out what I'm doing wrong.


Solution

  • You can set the contentType option to application/x-www-form-urlencoded, because the default value is application/json:

    $tabla.bootstrapTable({
        method: 'post',
        contentType: 'application/x-www-form-urlencoded',
        ...
    });
    

    Here is a related issue: https://github.com/wenzhixin/bootstrap-table/issues/918