Using server-side SearchPanes without an editor license

Using server-side SearchPanes without an editor license

dgruskadgruska Posts: 27Questions: 8Answers: 0
edited February 2022 in SearchPanes

I have been having a heck of a time trying to get this to work, and now the errors I’m getting seem to indicate that I don’t have a valid license, though it appears that just using the Editor for SearchPanes should be free.

"We provide SearchPanes server-side processing integration with our Editor server-side libraries. These libraries are open source and do not require an Editor license to operate"
- https://datatables.net/extensions/searchpanes/serverside

(node:4272) UnhandledPromiseRejectionWarning: TypeError: Editor is not a constructor
https://datatables.net/forums/discussion/55292/fn-datatable-editor-is-not-a-constructor

I know this is not the exact same issue, but I can’t find anything related to SearchPanes with this error.

I also tried following the instructions at https://datatables.net/blog/2017-08-31 , but there is no "install.js" file in my installation.

I am using the latest versions of DataTables, SearchPanes, Select, and Editor, and Node 14 (the latest Node version would work with the editor install due to sqlite3, it appears).

Any advice would be greatly appreciated.

Thanks,
Dave

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    Yep, you only need a license for the client-side Editor files, not the server-side scripts. This blog post should help - it's a more recent post with specific examples on how to get SearchPanes working.

    Colin

  • dgruskadgruska Posts: 27Questions: 8Answers: 0

    Thanks, colin. This got me further along. I realized that I was mixing two examples together, and I needed to include the line:

    let Editor = e.Editor;

    and I guessed that I also needed the following line:

    let SearchPaneOptions = e.SearchPaneOptions;

    Now, though, even with the simplest example, I am getting the following error "Cannot read property 'data' of undefined" - see below. Would this be related to the lack of the install.js file?:

    (node:19184) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined
        at Editor.<anonymous> (C:\Program Files\iisnode\www\datatables\node_modules\datatables.net-editor-server\dist\editor.js:1331:47)
        at step (C:\Program Files\iisnode\www\datatables\node_modules\datatables.net-editor-server\dist\editor.js:56:23)
        at Object.next (C:\Program Files\iisnode\www\datatables\node_modules\datatables.net-editor-server\dist\editor.js:37:53)
    

    I am using the following code in IISNode:

    const db = require('knex')({
      client: 'mysql2',
      connection: {
        host : '[servername]',
        port : 3306,
        user : '[username]',
        password : '[password]',
        database : '[db name]'
      }
    });
    
    let express = require('express');
    let app = express();
    let router = express.Router();
    
    let e = require('datatables.net-editor-server');
    let Editor = e.Editor;
    let Field = e.Field;
    let Validate = e.Validate;
    let Format = e.Format;
    let SearchPaneOptions = e.SearchPaneOptions;
    
    router.all('(/*)', async function (req, res) {
        /* NOTE: knex test works
        response = await db.select('id', 'partno').from('ord_feedthroughs').then(function (thisData) {
            res.json(thisData);
        });
        */
    
        // basic Editor test
        let editor = new Editor(db, 'ord_feedthroughs', 'ord_feedthroughs.id').fields(
            new Field('ord_feedthroughs.partno')
        ).write(false);
    
        await editor.process(req.body);
        res.json(editor.data());
    });
    
    app.use(router);
    app.listen(process.env.PORT, function(err){
        if (err) console.log(err);
        console.log("Server listening on PORT", process.env.PORT);
    });
    
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Would this be related to the lack of the install.js file?

    No - that shouldn't cause an issue. I aren't using the Editor client-side Javascript files which is what the install.js file puts into place.

    There might be two issues:

    1) On the client-side are you using POST data for the Ajax request - e.g.

    ajax: {
      url: '...',
      type: 'POST',
    }
    

    If not - do that, since you are using req.body for the data processing.

    2) I don't see anything there for processing the submitted data. You probably need something like this around line 15 in the above code:

    const bodyParser = require( 'body-parser' );
    
    app.use( bodyParser.urlencoded({ extended: true }) );
    

    Allan

  • dgruskadgruska Posts: 27Questions: 8Answers: 0

    Thanks, Allan. I did have 'POST' specified, but I didn't have the bodyParser code.

    This got me to a new error:

    Cannot read property 'length' of undefined

    (node:10444) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
        at Editor._sspSort (C:\Program Files\iisnode\www\datatables\node_modules\datatables.net-editor-server\dist\editor.js:1783:42)
        at Editor.<anonymous> (C:\Program Files\iisnode\www\datatables\node_modules\datatables.net-editor-server\dist\editor.js:1672:30)
    

    Length is being passed in, if that's what it is referring to:

    I took another look at https://datatables.net/examples/server_side/post.html , and I have everything set up the same way. Also, server-side processing works for me as long as I don't try to integrate SearchPanes.

    I really appreciate the help.

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

    Could you give me a link to your page please? If that isn't possible, can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is. That might give me enough of a clue as to what is going on.

    Thanks,
    Allan

  • dgruskadgruska Posts: 27Questions: 8Answers: 0

    I'm unable to post a link, but here's the debugger code:

    ugenen

    Thank you.

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

    Thanks for that. What version of the Editor server-side libraries are you using please? Line 1783 in the current release wouldn't throw the error that is indicated above.

    Unfortunately, the debugger doesn't have anything that immediately stands out to me as a problem.

    Allan

  • dgruskadgruska Posts: 27Questions: 8Answers: 0
    edited February 2022

    Hi allan,
    I had downloaded Editor from here on the day 2.0.6 came out. I checked the code, though, and it didn't match up to the link you provided (it didn't match with 2.0.5 either). I then downloaded the "dist" folder from the link you provided, and replaced my previous download with this code. I then restarted Node, and now get the following error (same error, different line number):

    (node:5276) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
        at Editor._sspSort (C:\Program Files\iisnode\www\datatables\node_modules\datatables.net-editor-server\dist\editor.js:2007:42)
    

    which would produce the "length" error in the latest version:

    lines 2006-2011:
    Editor.prototype._sspSort = function (query, http) {
    for (var i = 0, ien = http.order.length; i < ien; i++) {
    var order = http.order[i];
    query.orderBy(this._sspField(http, order.column), order.dir === 'asc' ? 'asc' : 'desc');
    }
    };

    Thanks for your help.

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

    Thank you. It is possible you updated the client-side Editor, but not the server-side libraries?

    The error you are seeing suggests that no ordering information is being sent to the server as part of the server-side processing request. There isn't any in the parameters in the screenshot shown above, but they might just have scrolled off.

    Could you do:

    res.json(req.body);
    return;
    

    At the top of your controller please? And then send me the response from the server - that will let me see what it is sending, under the assumption that the server is decoding it correctly (which this will also test).

    Thanks! Sorry this is taking so long to solve this one - node installs are normally really easy :)

    Allan

  • dgruskadgruska Posts: 27Questions: 8Answers: 0
    edited February 2022

    Allan,
    No worries about the time - I am really glad you are helping me. I initially thought it might be the blank data field for the first column (we are doing this for the responsive arrows), but I removed it, and still get the same error.

    {
        "draw": "1",
        "columns": [{
            "data": "",
            "name": "",
            "searchable": "true",
            "orderable": "false",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "IMAGEURL",
            "name": "",
            "searchable": "true",
            "orderable": "false",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "VOLTAGEKV",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "VOLTAGEKVPLUG",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "AMPS",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "AMPSPLUG",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "NUMOFCONDUCTOR",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "CONDUCTORMATERIAL",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "CONDUCTORDIAMETER",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "STYLE",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "FLANGEMOUNTING",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "WELDLIPDIAMETER",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "WELDLIPTHICKNESS",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "WELDLIPMATERIAL",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }, {
            "data": "INSULATORMATERIAL",
            "name": "",
            "searchable": "true",
            "orderable": "true",
            "search": {
                "value": "",
                "regex": "false"
            }
        }],
        "start": "0",
        "length": "50",
        "search": {
            "value": "",
            "regex": "false"
        }
    }
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

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

    Got it now! Thanks very much for that. It is caused by the order: [] in your initialisation for the table. The result is that there is no ordering information sent to the server, but the server-side processing script doesn't take account of that possibility.

    I've committed a fix and if you gap the latest compiled editor.js file and drop it into node_modules/datatables.net-editor-server/dist/editor.js that should fix the issue. It will be part of Editor 2.0.7.

    Regards,
    Allan

  • dgruskadgruska Posts: 27Questions: 8Answers: 0
    edited February 2022

    Thanks for all your assistance, Allan. I am now getting data back! It's in a different format (wrapped with the table name, and bits are nested within another "data"), but I think I can re-write my code to handle that, or I can look into how to format the data differently. In any case, I think this an Express issue at this point.

Sign In or Register to comment.