Grabbing datatables' search object before it passes to search
Grabbing datatables' search object before it passes to search
STEP ONE
I have a server-side DataTables initialization. After initializing, I replace the column headers with search fields:
$('#table thead th').each( function () {
var title = $(this).text();
var html = $(this).html();
$(this).html( '<textarea id="'+ search_field +'" />');
});
STEP TWO
I tie a separate function into when the user types data into this header, and I create this dt_object
table.columns().every( function () {
var that = this;
$( 'textarea', this.header() ).on( 'keyup change paste', function () {
search_field = $(this).attr('id');
search_value = (this.value).replace(/'/g,"\\'");
dt_object = that;
});
});
STEP THREE
Later on I call this specific function, which takes the user's search term and fires off the .search and .draw() options of dt_object.:
function execute_datatables_search(dt_object, search_term) {
dt_object
.search( search_term )
.ajax.url(global_base_url + '/api/datatables_search')
.draw();
}
STEP FOUR
This works fine. In the header request that gets sent over to the datatables_search api, I see this:
{
draw: 3
columns[0][data]:
columns[0][name]:
columns[0][searchable]: true
columns[0][orderable]: false
columns[0][search][value]:
columns[0][search][regex]: false
columns[1][data]:
columns[1][name]:
columns[1][searchable]: true
columns[1][orderable]: true
columns[1][search][value]:
}
I'm trying to hit a point in between steps 3 and 4 and review the values that are going to be populated into these columns[] variables - but I can't seem to parse out the dt_object object and find any information in there (it's a really big object...). I would assume that these are all a part of the dt_object object I'm creating up in step two - but I don't see anywhere in this object that tells me Okay, the user is searching column 4, which is "user", for the value "Alan" , however I see that in the POST info once I submit the request.
Where is this data and how do I access it so I can verify it's building correctly? (It's not right now - there's something going on with my logic that is causing search fields to get populated with data when I don't want them to...)
This question has an accepted answers - jump to answer
Answers
Hi @lordterrin ,
There's a lot going on there. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin