MBaas
MBaas

Reputation: 7530

Why is yadcf custom_filter not working?

Fiddle: https://codepen.io/MBaas/pen/rpZZzd

I have a Datatable about newspapers endorsements for presidential candidates that I want to filter on the party - a value that is not contained in the table (I have shortcodes "D" or "R" in the table but would like to use text "Democrat" or "Republican" in the UI). This may have once worked (I think it did) - but after upgrading to beta 0.9.1 it stopped. Possibly a bug in the beta - or possibly an undetected bug in my code?

My fn:

function myCustomFilterFunction(filterVal,columnVal,rowValues,stateVal)
 {
 console.log(rowValues);
 console.log(filterVal+'/'+columnVal);
 if (columnVal === '') { return true;}
 return -1 < columnVal.search(filterVal);
 }

I had added the log for debugging purposes and it produced this output (excerpt):

["Wisconsin State Journal", "2016", "Clinton", "", "", "", ""]
"D/"

I was surprised to see columnVal being empty. That explained filtering not working, and it being empty can be explained by looking at rowValues. But given that the source-data was defined in JSON as

["Wisconsin State Journal",2016,"Clinton","http:\/\/host.madison.com\/wsj\/opinion\/editorial\/our-endorsement-hillary-clinton-america-must-get-this-right\/article_b526fe64-c2ca-5e3d-807a-0ef4ae23a4d5.html","","","D"]

this is odd. Could it be related to the fact that the column is not visible?

Upvotes: 0

Views: 298

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58900

You should make column containing party short code searchable with searchable: true option otherwise your custom filtering function won't work.

For example:

{"searchable":true, "title":"Party (Shortcode)", "visible":true}

See updated example for code and demonstration.

Upvotes: 2

Related Questions