rifanece / jquery-datatables-column-filter

Automatically exported from code.google.com/p/jquery-datatables-column-filter
0 stars 0 forks source link

Server-side compatibility with the last DataTables.js version (1.10.x) #158

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

I corrected the plugin. Just simple modifications that permits it compatibility 
with the last version of DataTables from line 790 to 820 :

if (oTable.api().settings().context[0].bAjaxDataGet) {

                var fnServerDataOriginal = oTable.api().settings().ajax;

                oTable.api().settings().ajax = function (data, callback, settings) { 

                    for (j = 0; j < aiCustomSearch_Indexes.length; j++) {
                        var index = aiCustomSearch_Indexes[j];

                        for (k = 0; k < data.length; k++) {
                            if (data[k][searchable] === true)
                                data[k][search][value] = afnSearch_[j]();
                        }
                    }
                    // We don't need because we don't trust the user input ;)
                    //aoData.push({ "name": "sRangeSeparator", "value": properties.sRangeSeparator });

                    if (fnServerDataOriginal != null) {
                        try {
                            fnServerDataOriginal(data, callback, settings, oTable.fnSettings()); //TODO: See Issue 18
                        } catch (ex) {
                            fnServerDataOriginal(data, callback, settings);
                        }
                    }
                    else {
                        $.getJSON(sSource, aoData, function (json) {
                            fnCallback(json)
                        });
                    }
                };

            }

Original issue reported on code.google.com by onrobin...@gmail.com on 2 May 2014 at 2:50

Attachments:

GoogleCodeExporter commented 9 years ago
Many thanks for this. This got my server-side filtering working, but for ranges 
no search values are being sent in the request. Since I am new to this software 
I don't know where this issue was introduced (original code or this patch). I 
am just not getting any parameter values through for range search values so I 
can't do the filtering on the server side for those fields.

Original comment by pmozi...@metamedia.us on 9 May 2014 at 9:28

GoogleCodeExporter commented 9 years ago
Range filtering didn't work for me either, with this solution -- I THINK it's 
because I'm using an object for the value of my "ajax" datatable setting, 
instead of a function. Eventually I replaced all the code above with:

if (oTable.api().settings().context[0].bAjaxDataGet) {

                $(oTable[0]).on('preXhr.dt', function ( e, settings, data ) {
                    for (j = 0; j < aiCustomSearch_Indexes.length; j++) {
                        var index = aiCustomSearch_Indexes[j];

                        if ($.fn.dataTable.ext.legacy.ajax) {
                            for (var key in data) {
                                if (key == "sSearch_" + index)
                                    data[key] = afnSearch_[j]();
                            }
                        } else {
                            for (k = 0; k < data.length; k++) {
                                if (data[k][searchable] === true)
                                    data[k][search][value] = afnSearch_[j]();
                            }
                        }
                    }
                    console.log(data);
                } );

            }

which seemed to work.

Original comment by p...@silvertree-capital.com on 20 May 2014 at 11:25

GoogleCodeExporter commented 9 years ago
Oops, I left a trailing console.log line that can be removed.

Original comment by p...@silvertree-capital.com on 20 May 2014 at 11:25

GoogleCodeExporter commented 9 years ago
Silvertree-

Thank you very much for your patch. I was tearing my hair out over this one. Do 
you (or anyone else) know when this might be integrated into the release 
version?

-Josh

Original comment by j...@wiz4.us on 20 Aug 2014 at 1:48

GoogleCodeExporter commented 9 years ago
Hi, 
in your experience, this the only change to do to use 
jquery-datatables-column-filter
with DataTables 1.10 ?
As I see the official trunk is stopped at March so the last version doesn't 
work with DataTables 1.0

Original comment by ztaj...@gmail.com on 2 Oct 2014 at 2:29

GoogleCodeExporter commented 9 years ago
Yes.

But now, I andonned this jQuery plugin to be fully compatible with the last 
version. I fully generate individual column filters with my server language 
(PHP). I write a librairie available.
DOc : http://www.robin-d.fr/DataTablesPHP/
Source : https://github.com/RobinDev/DataTablesPHP

I kept the same logic except I don't yet add the capability to generate select 
option from the data. It will come soon.

Original comment by onrobin...@gmail.com on 16 Nov 2014 at 10:53