Datatable searchbuilder hide empty value from dropdown

Datatable searchbuilder hide empty value from dropdown

ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1

Hi, i m using datatables with searchbuilder, i have a column with those values possible :

if (data == null) {
return null;
} else if (data == "1") {
return "✔";
} else if (data == "2") {
return "✖";
}

i would like when i select equal to in seachbuilder, that the empty value doesn't show (because it's already possible to select empty value with the empty option so there is no reason to show in the equal to option). How can i do this ?

Thx for your time / Answer :)

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Hi,

    I'm afraid there is no option to hide specific values in SearchBuilder at this time.

    Allan

  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1
    edited January 29

    Ok but why do i have a blank value there ? is the value is null in the database and if i set up my render like this :

    render: function (data, type){
                        if (type === "display"){
                            if (data == "1") {
                                return "✖";
                            } else if (data == "2") {
                                return "✔";
                            }
                        } else if (type === "sort" || type === 'filter' ){
                            if (data == "1") {
                                return "1";
                            } else if (data == "2") {
                                return "2";
                            }
                        }
                        return data;
                    }
                },
    

    it should show only ✖ and ✔ ? I don't understand why blank value is an option, can you explain pls ?

    If i select the blank value in the seachbuilder, this error happen and nothing change in the displayed data result :

    Thank in advance for your help,
    Mathieu

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    Answer ✓

    Something is always returned from the function. In Javascript when there is no return statement the function return undefined. You can see it with this example:
    https://live.datatables.net/nojucevo/1/edit

    You have this:

                        if (type === "display"){
                            if (data == "1") {
                                return "✖";
                            } else if (data == "2") {
                                return "✔";
                            }
                        }
    

    If the value is not 1 or 2 then the function will return undefined because you haven't defined a "default" return value. Try returning an empty string like this:

                        if (type === "display"){
                            if (data == "1") {
                                return "✖";
                            } else if (data == "2") {
                                return "✔";
                            }
                            return "";
                        }
    

    This should stop the error from occurring and will reset the search back to nothing, ie, display all rows.

    Kevin

  • ECEGROUPEECEGROUPE Posts: 77Questions: 28Answers: 1

    Thank you, it work correclty with this modification :smile:

Sign In or Register to comment.