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

custom_func with input(datepicker) instead of select #409

Closed
THPUG opened this issue Jun 15, 2017 · 17 comments
Closed

custom_func with input(datepicker) instead of select #409

THPUG opened this issue Jun 15, 2017 · 17 comments

Comments

@THPUG
Copy link

THPUG commented Jun 15, 2017

Thanks for a great tool! we use a lot in our project!

I want to implement a custom function where a single input (datepicker) will evaluate if the given date is between 2 dates which are in 2 different columns in my table.

If true - only the rows where the given date is between will be shown.

Unfortunately the only form element available is auto-generated box.

@vedmack
Copy link
Owner

vedmack commented Jun 15, 2017

custom_func was design for single column search, but now when I think of it you can use the third argument rowValues of the myCustomFilterFunction , please try using the custom_func with the given argument and if it will fit your need I will try to add date_custom_func filter

@THPUG
Copy link
Author

THPUG commented Jun 15, 2017

Thanks for the quick reply!

I was planning of using the rowValues.

the problem I face when using the 'custom_func' is there is no option of any other arguments beside the select-box while I need an input field - which i can configure as datepicker.

For example, if a user wants to search the date '30/08/2017' the date will then be evaluated for each row in the table to see if it falls between any pair of dates e.g. 20/08/2017 & 26/09/2017 = true.

i simple cant provide the user with a input field to select the date '30/08/2017' as the auto-generated select-box most probably have '20/08/2017' as an option which result in false.

Maybe i miss something about the option of providing the argument from another field.

@vedmack
Copy link
Owner

vedmack commented Jun 15, 2017

my question to you is - does the myCustomFilterFunction with the rowValues works fine for you in your scenario, if it does adding a datepicker that will fire myCustomFilterFunction on date select shouldn't be a problem

@THPUG
Copy link
Author

THPUG commented Jun 15, 2017

Perfect! will give a try now and let you know.

Nevertheless, it would be great to see a single datepicker that search between two columns with dates,
I believe its a common scenario.

thanks again!

@THPUG
Copy link
Author

THPUG commented Jun 15, 2017

Update.

Unfortunately i was unable to specific the function from inside datepicker 'onSelect' as it missing the needed arguments (columnVal, rowValues) while inti i use the following code:

yadcf.init(t, [{
column_number: 0,
filter_type: "custom_func",
filter_container_id: "settings-hr-teams-positions-table-date-range",
custom_func: settingsHrTeamsListDateSearch
}],
{ externally_triggered: true});

Now if i use these settings with datepicker option:
$("#settings-hr-teams-positions-search-date").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: "1900:2100",
onSelect: function(dateText, inst) {
console.log('table draw', dateText);
settingsHrTeamsListDateSearch(dateText, columnVal, rowValues);
}
});

It is expected that the data in 'columnVal' & 'rowValues' is empty \ not exist.

@vedmack
Copy link
Owner

vedmack commented Jun 15, 2017

@THPUG that wasn't what I meant, never mind, I will try to add the date_custom_func filter

@THPUG
Copy link
Author

THPUG commented Jun 15, 2017

Thanks @vedmack.

I will be happy to understand what you meant to do as im using you plugin a lot - knowing its true capabilities will be very helpful.

vedmack added a commit that referenced this issue Jun 18, 2017
@vedmack
Copy link
Owner

vedmack commented Jun 18, 2017

filter_type: "date_custom_func" @0.9.2.beta.13 , go party and let me know if something is missing...

@vedmack vedmack closed this as completed Jun 18, 2017
@THPUG
Copy link
Author

THPUG commented Jun 19, 2017

Hi Daniel,

thank you very much for your affort!

I got this error message when trying to init the new filter:
'exGetColumnFilterVal error: no such filter_type: date_custom_func'

Of course i've garbed the new version 0.9.2.beta.13.

UPDATE 1.
everything is working now beside the 'x' button to clear the datepicker box which return the error message mention above.
'exGetColumnFilterVal error: no such filter_type: date_custom_func'

UPDATE 2.
I guess the problem is with datepicker object which return the last date in the input element instead of empty string - the second time i've click the "X" button the table rows shows okay.

@THPUG
Copy link
Author

THPUG commented Jun 19, 2017

Wanted to share my solution with everyone in case you need it:
I have a table with 2 columns [0] & [1]
[0] = start date
[1] = end date
I need to evaluate if A giving date is between start & end dates.

The bellow code will add a filter container, init the yadcf plugin & evaluate column 0 VS 1

//date range search container
$("#"+tableID+"_wrapper .ui-corner-tr").append('<div class="datatable-date-range-box" id="myfilterID"></div>');

//Init yadcf (t = my datatable)

yadcf.init(t, [{
        column_number: 1,
        filter_type: "date_custom_func",
        date_format: "dd/mm/yyyy",
        filter_container_id: "myfilterID",
        custom_func: mySpecialFunction
    }]);
function mySpecialFunction(filterVal, columnVal, aData, stateVal){
    var date = parseDate(filterVal);
    var start = parseDate(aData[0]);
    var end = parseDate(aData[1]);

    var found;
    if (filterVal === '') {
        return true;
    }

    if (start <= date && date <= end) {
     console.log('between dates');   
      found = 1;
    } else {
        console.log('NOT between dates');   
      found = -1;
    }

    if (found !== -1) {
        return true;
    }
    return false;
}

@vedmack vedmack reopened this Jun 19, 2017
@THPUG
Copy link
Author

THPUG commented Jun 20, 2017

Found another bug in this version.

After initial the first time using: filter_type: "date_custom_func" - next datatable im loading regardless the use of yadcf will not load with error:
`Uncaught TypeError: obj.table is not a function

at Object.generateTableSelectorJQFriendly2 (jquery.dataTables.yadcf.js?10504:690)
at Array.<anonymous> (jquery.dataTables.yadcf.js?10504:1246)
at yb (jquery.dataTables.min.js?10504:908)
at ha (jquery.dataTables.min.js?10504:899)
at R (jquery.dataTables.min.js?10504:616)
at ia (jquery.dataTables.min.js?10504:1040)
at HTMLTableElement.<anonymous> (jquery.dataTables.min.js?10504:2045)
at Function.each (jquery-3.1.0.min.js:2)
at r.fn.init.each (jquery-3.1.0.min.js:2)
at r.fn.init.m [as dataTable] (jquery.dataTables.min.js?10504:1877)`

@vedmack
Copy link
Owner

vedmack commented Jun 20, 2017

@THPUG please provide a test case (page) for the "another bug"

@wynstep
Copy link

wynstep commented Jun 20, 2017

I am also encountering this bug! It appears when I use 'date_range'. It does not appear with the other types of filters

@THPUG
Copy link
Author

THPUG commented Jun 20, 2017

Im currently using only 'date_range' & 'date_custom_func'.
I've tried to provide with jsfiddle but was unable to set it up with the latest version of yadcf.

Moreover, when trying to clear the datepicker input using the 'x' button - nothing occur.

@THPUG
Copy link
Author

THPUG commented Jun 22, 2017

Hi @vedmack

Do you know when this gonna be fixed?

@vedmack
Copy link
Owner

vedmack commented Jun 22, 2017

@THPUG fix for the reset button will be committed in the following days, as to the other issues - I will be able to help you only after test case

@vedmack
Copy link
Owner

vedmack commented Jun 23, 2017

@THPUG @wynstep I fixed the reset button, as to the other issues related you will have to provide a working jsfiddle / jsbin so I will be able to reproduce it, without it I can't really help

vedmack added a commit that referenced this issue Jun 25, 2017
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

3 participants