ajax.data and seach, style of writing
ajax.data and seach, style of writing
 marcpirat            
            
                Posts: 51Questions: 18Answers: 0
marcpirat            
            
                Posts: 51Questions: 18Answers: 0            
            I checked this example to be able to do a search after init table (server side processing ): http://live.datatables.net/gelazeba/1/edit
I created this code
var urlI18n = '/i18n/' + '[(${#authentication.getPrincipal().getLang()})]' + '.json';
                var url = "/search";
                var tableConfig = {
                    "searching" : false, 
                    'columns': [
                        {'data': 'id'}, 
                        {'data': 'buildDate'}
                    ],
                    language: {
                        "url" :  urlI18n
                    },
                    'bLengthChange': false, //hide 'show entries dropdown
                    'processing': true,
                    'serverSide': true,
                    'pagingType': 'simple_numbers',
                    'dom': 'tp',
                };
                var searchSamplingsResultsTable = $("#searchSamplingsResultsTable").DataTable(tableConfig);
                $("#searchSamplingsResultsTable").on('click', function () {
                    tableConfig.ajax={
                        "url" : url
                    };
            /*
            tableConfig.ajax.data={
                        var current = $('#searchSamplingsResultsTable').DataTable();
                        d.page = (current != undefined) ? current.page.info().page : 0;
                        d.size = (current != undefined) ? current.page.info().length : 5;
                        d.sort = d.columns[d.order[0].column].data + ',' + d.order[0].dir;
                        d.search=d.search.value;
                    };
                    tableConfig.search = {
                        d.form = $("#searchSamplingsForm").serializeArray()
                    };
                    */
                    searchSamplingsResultsTable.destroy();
                    searchSamplingsResultsTable = $('#example').DataTable( tableConfig );
                });
How I need to write tableConfig.ajax.data and  tableConfig.search?
Seem like should be wrote with json style
This discussion has been closed.
            
Answers
Hi @marcpirat ,
The problem with the example is that
searchingis disabled, so no searching will take place. If you comment out that option, as I did here, the load works as expected.Cheers,
Colin
"searching" : false was there to remove the input for searching...
real problem is more about that
Hi @marcpirat ,
I'm not clear what the problem is! If you could link to a test page, and explain what the issue is, we can take a look,
Cheers,
Colin
I have a form for the search... user can search by many field, that why I created tableConfig.search.
In tableConfig.ajax.data, I try to do the bridge between frond end and backend, they don't use same name parameter.
with this code I get
Uncaught SyntaxError: Unexpected identifier
This means you have a syntax error. The error is the way you are making the assignments within the curly braces
{}. This represents an object. Take a look at this page which explains how to make assignments within the{}. Also take a look at the example you posted, the syntax is different than yours.Kevin
you not posted link...
for the link i posted they use a json style...
habitually i do
Sorry, here is the link:
https://www.w3schools.com/js/js_objects.asp
The difference in your last example is you are not setting object values but using a function.
Kevin
tried
Cannot read property '0' of undefined
http://live.datatables.net/fepidego/1/edit
The problem is because
datais trying to reference d (d.columns[d.order[0].column].data) but d is an empty object on entry - see this here with debug.I want to use this way to connect data from sqlsrv source but not ajax / objects_root_array.txt, what should I do?
@rainkv - your question isn't very clear. I suggest you start a new thread and give a better explanation.