Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date range filter not working with function as data #262

Closed
khung opened this issue Nov 30, 2015 · 5 comments
Closed

Date range filter not working with function as data #262

khung opened this issue Nov 30, 2015 · 5 comments

Comments

@khung
Copy link

khung commented Nov 30, 2015

I'm trying to use the range_date filter with a function in either the columns.render property or the columns.data property of the DataTable. However, yadcf does not seem to work with either one. This seems related to issue #95 but the script does not even reach the changed code.

Using a function in the columns.render property gives incorrect filter results as yadcf uses the _aData value rather than the _aFilterData value:

var table = $("#reqtable").DataTable( {
    "ajax": 'test.txt',
    "columnDefs": [
        {
            "targets": 0,
            "render": function ( data, type, row, meta ) {
                var jsDate = new Date(row[0] * 1000);
                return $.datepicker.formatDate("mm/dd/yy", jsDate);
            }
        }
    ]
} );
yadcf.init(table, [
    {   column_number: 0,
        filter_type: "range_date"
    }
]);

Using a function in the columns.data property throws an error "dot_refs.split is not a function":

var table = $("#reqtable").DataTable( {
    "ajax": 'test.txt',
    "columnDefs": [
        {
            "targets": 0,
            "data": function ( row, type, val, meta ) {
                if (type !== 'set') {
                    var jsDate = new Date(row[0] * 1000);
                    return $.datepicker.formatDate("mm/dd/yy", jsDate);
                }
            }
        }
    ]
} );
yadcf.init(table, [
    {   column_number: 0,
        filter_type: "range_date"
    }
]);
@vedmack
Copy link
Owner

vedmack commented Nov 30, 2015

please provide a minimal jsbin that reproduces the issue to speed up the fix.

@khung
Copy link
Author

khung commented Nov 30, 2015

I'm not certain if this is the proper way to create the jsbin, but this should be all the code needed:
https://jsbin.com/tihumilehu/edit?html,js
The columns.data example does not seem to work with DOM-sourced data, and JS Bin does not seem to have a way to get AJAX-sourced data. Hopefully you can test that in some other way.

@vedmack
Copy link
Owner

vedmack commented Dec 1, 2015

you can use a static file to feed the ajax source, just like I did in the showcase see second table, you can get the sources of the showcase from its github repo .

Or you can also provide a link to your webapp

@khung
Copy link
Author

khung commented Dec 1, 2015

Thanks for the hint. I've tweaked the jsbin to work with AJAX:
https://jsbin.com/samoxiyegi/edit?html,js,console,output
You can add/remove the leading / in the //* lines to comment or uncomment the columns.render and columns.data properties to see the behavior of either one.

@vedmack
Copy link
Owner

vedmack commented Dec 17, 2015

fixed in 0.8.9.beta.30 , see jsbin sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants