add a function to search input before search start ,

add a function to search input before search start ,

amirrr00amirrr00 Posts: 3Questions: 1Answers: 0

hi , i want to change my input numbers to persian before my datatable search start , i write the function , but i don't know where should i place it , my function always work after datatable search the table , and i should click on the input again to see the rows that show my answear , for simplicity of my question , how could i add a function to datatable before its original search function start , srry for the bad english :)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    Answer ✓

    Do you mean as the user is typing you are converting Roman numerals to Persian? And you want that to happen before DataTables’ search starts? Your best option is probably to use your own input element with an input event handler that does your conversion and then triggers a call to the search() method (instead of typing to modify the build in search box).

    Allan

  • amirrr00amirrr00 Posts: 3Questions: 1Answers: 0

    thanks for the answer , i search for the input in the source code for three days and i couldnt do any thing do it , but your solution seem to work for me , thanks again ,

  • amirrr00amirrr00 Posts: 3Questions: 1Answers: 0

    your solution work for me ,
    first we should remove the default search input from data table dom by removing f ,
    then add our custom input like

    and then in the script add ,
    var table1=$('#example1').DataTable({
    "dom": '<"top"i>rt<"bottom"lp><"clear">',
    });
    $("#mySearchText1").bind("keyup", function(e) {
    let map = {
    '0' : "۰",
    '1' : "۱",
    '2' : "۲",
    '3' : "۳",
    '4' : "۴",
    '5' : "۵",
    '6' : "۶",
    '7' : "۷",
    '8' : "۸",
    '9' : "۹"
    };

                this.value = this.value.replace(/[0123456789]/g, function(match) {
                    return map[match]
    
                });
                table1.search(this.value).draw();
            });
    

    , thanks for your help allan

This discussion has been closed.