Pass extra parameter(s) with datatable (server-side)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Pass extra parameter(s) with datatable (server-side)

MoveOn
Hi!

I have datatable that is server-side driven and use pager, filter, etc. on my form.

When action is made (ex: next page) an ajax call with all the data that datatables needs is commited to my Spring controller.
Now I also have additional hidden field in my form that I need to pass to controller each time some action is made on datatable.

Any clues? Thanks!

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pass extra parameter(s) with datatable (server-side)

Thibault Duchateau
Administrator
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pass extra parameter(s) with datatable (server-side)

MoveOn
I still strugle with this problem and I could not find a solution or what I am doing wrong. Hope I could get some help here.

My scenario is:
- submit form with ajax and get back updated one.
- reload datatables (outside of form) to load data related to checkbox value.

When I submit form and come back in ajax success block everything is fine.
- I replace form html with updated one.
- Alert shows correct value of selected checkbox.
- Datatables is reloaded successfully.
However, bundle with same code does not pick value of checkbox. And I dont get correct value in controler, to filter my datatables result.

Dont know why data of checkbox is not picked by datatables bundle JS?


CODE:

So my ajax call for form is like this:

function doClick() {
var str = $("#form").serializeArray();
               
$.ajax({
   type:"GET",
   data:str,
   url:"form",
   async: true,
   success: function (response) {
      $("#formWrapper").replaceWith(response);  
      alert("Test data: " + document.getElementById('checkbox').value);
      var table = $('#myTableId').DataTable();
      table.ajax.reload(null,true);
   },
   });
};


Dandelion datatable:

<datatables:table id="myTableId" url="/table" serverSide="true" ajaxParams="ajax#customAjaxParams">
   <datatables:column title="#" property="id" visible="false"/>
   <datatables:column title="Name" property="name"  />                                                       
</datatables:table>


Bundle:

function customAjaxParams(){
  return {
    "type" : "GET",
    "data" : { name:  document.getElementById('checkbox').value }
  }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pass extra parameter(s) with datatable (server-side)

MoveOn
I have tested it further on "datatables-jsp-ajax" project and I can tell that "ajaxParams" does not work with "reloadFunction".

How could I manage to send some values from page when I reload datatable?

Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pass extra parameter(s) with datatable (server-side)

MoveOn
I solved custom filtering with this code:

        function doClick() {
                var str = $("#form").serializeArray();
               
                $.ajax({
                    type:"GET",
                    data:str,
                    url:"form",
                    async: true,
                    success: function (response) {
                    $("#formWrapper").replaceWith(response);  

                    var table = $('#myTableId').dataTable();
                        var elt = document.getElementById('checkbox').value;
                        var tableColumnIndex = 3
                        table.fnFilter( elt , tableColumnIndex );  //filter & reload
                    },
                });
        };
Loading...