Node library implementation
Node library implementation
DesarrolloPREC
Posts: 34Questions: 4Answers: 0
Hi Allan
We are implementing editor with nodejs. The current versions that we are using are:
Nodejs: 9.5
knex: 1.4
We had installed datatables.net-editor-server from npm repositorys
The code of node is next
layer service
import db from '../../models/db';
const DBTABLE = 'schema.table_name';
import {
Editor,
Field,
Validate,
Format,
Options
} from 'datatables.net-editor-server';
async proccessAll(req, eliminado=false) {
try {
let editor = new Editor(db, DBTABLE).fields(
new Field('arl_nombre'),
new Field('arl_tipo'),
new Field('arl_vigente'),
new Field('arl_defecto')
);
return await editor.process(req.body);
} catch (error) {
throw error;
}
};
layer conrtoller
router.all('/proccess', async (req, res, next) => {
try {
//procesando la información...
const editor = await aerService.proccessAll(req);
//retornando...
res.status(200).json(editor.data());
} catch (error) {
res.status(400).json({
error: error.message
});
}
});
Is the exactly the examples of Node documentation, but, always we have this message: Cannot convert undefined or null to object
Please, can yoy help us?
Thanks a lot for you support
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I presume you've removed some other code for brevity? For example:
Is in a class I guess?
Can you show me the backtrace from the error? If you remove the
try / catch
that should show more error information.Also does the error happen when you load the table, add a new row, edit or delete?
Allan
Allan
Some ones additional software that we are using
Postgres: 9.5
Express: 4
Yes, It's a class. We are using a service layer for bussines control. But, this code was passed to controller layer and happened the same situation, following the exactly example of node documentation
Well, the code is next:
It's happen when we want to make a insert, update, delete, but for reading it's all ok
Sure, the trace of try catch trigger this information:
Thanks for your help
Regards
Allan
Really we were implementing in diferents forms to apply the examples with editor server. But in all ways shows those error before metioned.
Other point that forgot to tell you is that we are using with views engine.
Pug, handelbars or pure html, but we had those error in all of kind of views
Please, give us your advices
Waiting for you support
Regards
This is the line that is throwing the error:
Immediately before you call
editor.process
, could you add:and let me know the result that is printed out on the console?
I'm wondering if
extended: true
is missing where you use body parser - e.g.:Regards,
Allan
Allan
Thanks, you gived us a track.
The problem was in the bodyParse line... but in express give a similar line setting like this:
changed to:
and finally works perfect
Thanks a lot for your help
Regards
Allan
We are implementing editor full nodejs for a project, it's genial to fast developtment.
One more question, in the documentation give us a closer view to make sql oriented to conextion one DB... but we have to combinate columns of two DB in one table... Can we make this kind of joins?
The examples show to make joins of one especific DB. In our case, as I mentioned, we need to cross of other columns in distinct DB
Thanks for your help
This example shows two db fields being shown in a single DataTables column. Is that what you mean?
Allan
Allan
Well exactly that we are looking for the mehod that the editor allow literal o something similar, example
This kind of union we have the job using other orm that allow make sql string as a field, but our idea is to use full Editor library.
We still reading the documentation, but if you had a similar proble, anda you have the answer it would be a lot of help.
Thanks for you support
Regards
Hi,
Yes, I see what you mean. Unfortunately, at the moment in the NodeJS libraries for Editor, it doesn't support raw SQL statements in the field name. Some kind of ability to do that is something that I'm considering for the Node, PHP and .NET libraries, but haven't yet nailed that down.
Regards,
Allan
Allan
We hope that this option can implemented in the next version, would be a lot of help
Thanks for you support
Regards
Allan
It's me again, sorry -but is good news for all of you- we are implementig node library
Question
We're validating data with custom message, but nor in the examples can't had put the custom message, always appear: 'Input no valid'
We have followed the indications:
This alway show 'Input not valid', give us a help
Thanks
Regards
Allan
In the crud option, we don't have problems proccesing data, except with the delete option.
We are implementig a REST interface and following the node documentation explain, but, this method never processing
What is the cause?
We forgot something?
Here is the example in the class implementation:
We need to make a logical deletion, is the cause that we want to update the fields. We made a code trace, but never enter in the line of console.log.
This is the js to client level
As we mentioned to you, read, create, update there are no problem with those, the problem existing is in the delete option.
Thanks for your help
Regards
Your
Validate.Options
should be passed in as an option to the validator (notEmpty
in this case):Validation documentation is here.
Regarding the delete, depending n what your server is expecting, you might need to use
ajax.deleteBody
.Allan
Allan
Thanks for you reply
Logical deletion was made with a few changes. It's working
Message validation, doesn't work. We had putted the code as you had mentioned and doesn't work.
Even in the code example of nodejs library that we have to make testing
We had made testing, but it's not working, not with nonEmpty validation, this happen with other validations. Here is the validation that we try to use:
And the same way, editor response: 'Input not valid'
Please check if we are failing or something happen whit the editor code
Regards
minNum
checks that a numeric value is submitted - in the case above it will check for a number less than 5 and fail if found.Its signature is actually:
I missed the decimal parameter in the documentation which is why your example above isn't working. I'll get that fixed right now!
Allan
Allan
We still with this problem. The validation option doesn't show the custom message.
We putted a custom validator and the message show ok, but with the Validate.Options the message doesn't work and always show 'Input not valid'
Here is other validation option that we try to use:
Thanks for your help
Regards
Allan
Other cuestion, now over join tables.
Can we make a join tables not based in id column, that is, choose other column that not be colum id?
Example:
Regards
Hi,
Apologies for my confusion about the validation issue. I see the problem now and have committed a fix. I'm going to tag and release 1.7.4 which will contain this fix soon (this week).
Regarding your join question - yes you can join on other columns. For performance reasons it is best to join on indexed columns, so you might need to add an index, but that should work fine.
Allan
Allan
With respect to leftJoin method, we follow step by step the indications of node library to make a join table and as we commented to you, we need join other fieds that not be exactly 'id' field.
But we always recibed this message:
The sql example that we try to arm is next:
Give us your help, many thanks
Regards
I think it is the alias that is causing the issue. Could you try removing the
as reg1
part please (and updating the references to that table)?If that doesn't work, can you show me your full initialisation.
Thanks,
Allan
Thanks Allan
We are advancing in our projet with nodejs and editor...
Just one more question... in reference to uploadfiles. It tokes some time to resolve delete files. In the interface you putt a button with X to remove files, but it is not attach a event that we can controlled remove each one file.
To resolve this inconvenent, we putted in the event of field upload a event that can controll it. To resume this the little code
We made this kind of code because the event dessapear every time that one file is uploaded, and we need to set again the event for that not dessapear.
The cuestion is, It's correct that we are making?, can you put a event directly to the button X to remove file?
Thanks for your support
Regards
The reason for that is that the files information isn't sent to the server until the form is submitted. Only at that time do you know if a file can fully be deleted. E.g. consider two users using the same table - one deletes and image and the other reloads the table. The reference to the file would still be in the original row if it hasn't yet been submitted, but the file has been removed, resulting in an error.
Editor uses the concept of orphaned files to handle this.
Allan
Allan
We are trying to implement datatables and editor in client framework, especifctly using ionic 3. As you know, this framework it's make under angular
After some investigations to implemente, we resolved to problem for shows data in the datatable view
and works perfectly.... but with the editor present a problem.
First, we follow the instructions en readme file to install de editor zip file, but when we try to call from component ts the editor shows a error that indicate: jQuery is not defined
Please, give us a help, thanks
Regards
Does it throw that error on
this.table = jQuery('#idTable');
or somewhere else? Can you link to a page showing the issue please.Allan
Allan
Sorry, we are working in localhost server our project and couldn't putted in internet... we almost finish but the editor gived us a little trouble.
Exactly this is that happen
As we sayed to you, we can't call to the editor althoug we made a installation of and editor node_modules packages.
Datatables worlks perfectly
Thanks for your help
Regards
We remove those lines:
or
and the code runs without errors.
But if we put the lines of above, the page shows the next message:
```
What if you use:
Does that work? Or does that also give the same error?
Allan
Hi Allan
Yes, we putted and trigger the same error
Perhaps, we are forgot to put something in the ionic config json file or something else that we lost, and that you have an idea?
Regards
Allan
Well, finally works but without calling editor on the ts class
Putting this code works editor.
Thanks for you help
Regards
Allan
The other post was lost or do you have some kind of administration?
Thanks