I can not get the search function to work

I can not get the search function to work

BoomthaboxBoomthabox Posts: 19Questions: 3Answers: 0

I am trying to get my search function to work and I read this:
Add "searchable: false" to the first column configuration and it will start working!

I am not sure I put the "searchable: false" right where it should be but I hope someone can help me out and if this is the problem.

Link:
http://www.deltor.se/Editor-PHP-1.9.3/examples/simple/server-side-processing.html

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,133Questions: 1Answers: 10,399 Site admin
    Answer ✓

    Since you are using server-side processing (which is only really useful if you have 10k or more records), then the server doesn't know anything about your client-side generated columns - in this case your first one.

    So change:

                {
                    "className":      'details-control',
                    "orderable":      false,
                    "data":           null,
                    "defaultContent": ''
                },
    

    to be:

                {
                    "className":      'details-control',
                    "searchable":      false,
                    "orderable":      false,
                    "data":           null,
                    "defaultContent": ''
                },
    

    Allan

  • BoomthaboxBoomthabox Posts: 19Questions: 3Answers: 0

    Thanks! Now it is working :smile:

  • BoomthaboxBoomthabox Posts: 19Questions: 3Answers: 0

    Oh now I just added to use image uppload (upload-many.html) and now the search is not working again, what am I doing wrong here? Hahaha

        editor = new $.fn.dataTable.Editor( {
            ajax: "../../controllers/upload-many.php",
            table: "#example",
            fields: [ {
                    label: "First name:",
                    name: "users.first_name"
                }, {
                    label: "Last name:",
                    name: "users.last_name"
                }, {
                    label: "Phone #:",
                    name: "users.phone"
                }, {
                    label: "Site:",
                    name: "users.site",
                    type: "select"
                }, {
                    label: "Images:",
                    name: "files[].id",
                    type: "uploadMany",
                    display: function ( fileId, counter ) {
                        return '<img src="'+editor.file( 'files', fileId ).web_path+'"/>';
                    },
                    noFileText: 'No images'
                }
            ]
        } );
    
    
    var table = $('#example').DataTable( {
            dom: "Bfrtip",
            ajax: {
                url: "../../controllers/upload-many.php",
                type: "POST"
            },
            serverSide: true,
            columns: [
                {
                    "className":      'details-control',
                    "searchable":      false,
                    "orderable":      false,
                    "data":           null,
                    "defaultContent": ''
                },
                { data: "users.first_name" },
                { data: "users.last_name" },
                { data: "users.phone" },
                { data: "sites.name" },
                {
                    data: "files",
                    render: function ( d ) {
                        return d.length ?
                            d.length+' image(s)' :
                            'No image';
                    },
                    title: "Image"
                }
            ],
            select: true,
            buttons: [
                { extend: "pageLength" },
                { extend: "create", editor: editor },
                { extend: "edit",   editor: editor },
                { extend: "remove", editor: editor }
            ],
            "order": [[1, 'asc']]
        } );
         
        // Add event listener for opening and closing details
        $('#example tbody').on('click', 'td.details-control', function () {
            var tr = $(this).closest('tr');
            var row = table.row( tr );
     
            if ( row.child.isShown() ) {
                // This row is already open - close it
                row.child.hide();
                tr.removeClass('shown');
            }
            else {
                // Open this row
                row.child( format(row.data()) ).show();
                tr.addClass('shown');
            }
        } );
    } );
    
  • kthorngrenkthorngren Posts: 21,132Questions: 26Answers: 4,918

    Its hard to say just by looking at some code. What's happening? Doesn't look like your test case is updated with the file upload. Go through the debugging steps from your other threads and let us know what you find.

    Kevin

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    You would need to add seachable: false to the files column, as you did before.

    Colin

  • BoomthaboxBoomthabox Posts: 19Questions: 3Answers: 0

    Thanks for reply, I have "searchable": false, but maybe I have put it wrong in the code? I have tryed to find what is wrong but I can not see and maybe I do it wrong. I send the link so you can see the script in action :smile:

    "DataTables warning: table id=example - Unknown field: files (index 5)"

    http://www.deltor.se/Editor-PHP/examples/simple/server-side-processing_con.html

  • BoomthaboxBoomthabox Posts: 19Questions: 3Answers: 0
    edited June 2020

    Also to the script above (the link) I try to get upload image (upload-many) to work but get "A server error occurred while uploading the file", maybe you have the possibility to help me with this also, I don't know if there is a connection.

    Thanks in advance!

    /Alex

  • BoomthaboxBoomthabox Posts: 19Questions: 3Answers: 0

    I just saw I have "searchable": false, two times in the scrip so now it is working :smiley:

    But the problem with uploading files (images) is still there. Hope someone here can help me fix this problem :smile:

    "DataTables warning: table id=example - Unknown field: files (index 5)"

    http://www.deltor.se/Editor-PHP/examples/simple/server-side-processing_con.html

    Thanks in advance!

    /Alex

  • kthorngrenkthorngren Posts: 21,132Questions: 26Answers: 4,918

    As Colin said:

    You would need to add seachable: false to the files column, as you did before.

    Which is this column:

    ```js
    {
    data: "files",
    "searchable": false, // add this line
    render: function ( d ) {
    return d.length ?
    d.length+' image(s)' :
    'No image';
    },
    title: "Image"
    }
    ````

    Also to the script above (the link) I try to get upload image (upload-many) to work but get "A server error occurred while uploading the file",

    Look at the browser's network inspector to see what is returned. Steps in this technote. You will see this error:

    Warning: move_uploaded_file(/customers/4/b/0/deltor.se/httpd.www/uploads/13.png): failed to open stream: No such file or directory in /customers/4/b/0/deltor.se/httpd.www/Editor-PHP/lib/Editor/Upload.php on line 488 Warning: move_uploaded_file(): Unable to move '/run/tmp/phpJjvubn' to '/customers/4/b/0/deltor.se/httpd.www/uploads/13.png' in /customers/4/b/0/deltor.se/httpd.www/Editor-PHP/lib/Editor/Upload.php on line 488 {"fieldErrors":[{"name":"files[].id","status":"An error occurred while moving the uploaded file."}],"data":[]}

    Looks like the paths you defined aren't there or there is a permissions issue.

    Kevin

  • BoomthaboxBoomthabox Posts: 19Questions: 3Answers: 0

    Ok, thank you very much for the help! Very nice, now it is working perfect! I am new to this but must say very good forum, 5-stars :smile:

    /Alex

  • BoomthaboxBoomthabox Posts: 19Questions: 3Answers: 0

    Is it possible to use PDF files also to upload?

    /Alex

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    You should be able to use any file type, though you can also restrict the file types too. This example here, if you look at the "server script" tab, only permits image files,

    Colin

  • BoomthaboxBoomthabox Posts: 19Questions: 3Answers: 0

    The thing is that I would need to be able to upload any file type but mostly pdf, doc and xls files. Is that possible? What would I need to change?

    Also I would need to be able to list the uploaded files with a link on each to be able to open them in a new window, instead of "1,2,3 etc image(s)". Is this possible?

    /Alex

  • rf1234rf1234 Posts: 2,934Questions: 87Answers: 415

    The thing is that I would need to be able to upload any file type but mostly pdf, doc and xls files. Is that possible? What would I need to change?

    "but mostly" doesn't sound like a rule ... but anyway Colin gave you the answer. Please look at his linked example! It is one of the validators of the server script.

    The second question I don't understand. Do you mean to have a link in the data table?

  • rf1234rf1234 Posts: 2,934Questions: 87Answers: 415
This discussion has been closed.