searching column for bool

searching column for bool

thefnordlingthefnordling Posts: 6Questions: 1Answers: 0

hi allen. I am working on upgrading one of my apps to DT1.10. I am having a problem searching for boolean values in a column.

in 1.9.4 when i created my datatable, i assigned it to a variable called rTable and called rTable.fnFilter("false", 1); to find all rows where column 1 was false. In 1.10 i am calling rTable.column(1).search('false').draw();

column.search.draw works fine in 1.10 for strings - it just doesn't seem to work for bools - i have tried toggling case sensitivity, passing the value (false) vs the string ("false") and no luck. how should i be filtering this in 1.10?

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    edited July 2014

    Hi,

    Is your data actually the string false or is it a boolean false? If its a boolean, then you might have come across a bug in DataTables 1.10 here...

    Thanks,
    Allan

  • thefnordlingthefnordling Posts: 6Questions: 1Answers: 0

    it's an actual boolean type, not a string. I haven't tried the new data tags to facilitate searching - i was going to test that out tomorrow.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    I'll take a look into this when I get into the office tomorrow morning. I feel that this is likely a type issue here. Looking at the DataTables search API there is this. That 'cast' to string was don't to match the 1.9 behaviour, but it is possible there is something in the core filtering that has changed.

    I'll post back when I have a bit more information.

    Regards,
    Allan

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Hi,

    So this is certainly due to a change in DataTables core and how it handles "empty" data for filtering. It is transforming your false to an empty string, which is wrong. The fix for that is fairly trivial, but I think this has knock on implications that I'd like to consider. I'll sleep on it tonight and look at it again with fresh eyes tomorrow!

    Allan

  • thefnordlingthefnordling Posts: 6Questions: 1Answers: 0

    hi allan. somehow my dataTables_scrollBody div (that contains the body of the DT) is resizing when i increase the width of the browser window, but the dataTables_scrollHead and dataTables_scrollFoot are not resizing.

    each column in my grid has a fixed width specified (in em). I do not want the scrollBody div to resize, i want it to remain fixed in width.

    I have scrollX set to true, and autoWidth set to false- in 1.9.4 i would get the behavior i'm looking for, but it seems to be behaving differently in 1.10 - any ideas?

  • thefnordlingthefnordling Posts: 6Questions: 1Answers: 0

    aha! i was able to back into it from another example, i just needed to set a width in pixels of the div containing the datatable, and it no longer resizes the body of the table - no need to look into this further.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    That sounds interesting. Are you able to link me to a page showing that problem so I can investigate?

    Regarding the searching for a boolean issue - sorry for the delay on it! I'm going to look at it today!

    Allan

  • thefnordlingthefnordling Posts: 6Questions: 1Answers: 0

    i just noticed that table tools .fnGetSelectedData has some unexepected behaviors.

    if i select a row, then update the data for that row, and then call fnGetSelectedData - fnGetSelectedData returns the original object (not the most recent one reflecting the update)

  • thefnordlingthefnordling Posts: 6Questions: 1Answers: 0

    disregard - i had messed up my event handler, all is well.

  • KlapZaZaKlapZaZa Posts: 4Questions: 0Answers: 0

    Hi,

    Is the search problem solved?

    I have the same issue when I search on a boolean "false" or 0. The column().search() treats it as an empty string. Like you said, allan.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Not yet - it is coming though! It is top priority now that I'm managed to work through a few other issues.

    Allan

  • KlapZaZaKlapZaZa Posts: 4Questions: 0Answers: 0

    That sounds great. It is an excellent job with the new version :)

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Apologies for the delay in looking into this, but I'm happy with the solution now after trying a few options. The change has been committed and the nightly is now up to date.

    If you could give it a try out and see what you think, and let me know if you hit any issues (or even if you don't!) that would be great.

    Regards,
    Allan

  • KlapZaZaKlapZaZa Posts: 4Questions: 0Answers: 0

    Okay, I have now tried it out. It still does not work for me.

    I have tried following:

    Filter with .search( false ):
    Result: filter everything out.

    Filter with .search( true ):
    Result: filter everything out.

    Filter with .search( 0 ):
    Result: filter nothing.

    Filter with .search( 1 ):
    Result: Gets the correct ones with status 1.

    Am I doing something wrong? I could use a little help here.

  • KlapZaZaKlapZaZa Posts: 4Questions: 0Answers: 0

    For extra information:
    I use query serach/server side. The status column in my mySQL is a tinyint(1)

This discussion has been closed.