plug lokijs with datatables
plug lokijs with datatables
tycoons
Posts: 9Questions: 1Answers: 0
Hi Guys,
I am trying to integrate the base in json format of lokijs with datatables but it does not work you have an idea on how to do it?
json data are not really identical to datatables
thanks for your help
This discussion has been closed.
Answers
Can you post an example of the json format returned?
Kevin
'''{"filename":"Objet.json","collections":[{"name":"candidats","data":[{"candidature":"site internet","nom":"hbwcf","poste":"Collaborateur junior","service":"Service Révision PME & Grandes Entreprise","Entree_le":"2018-11-16","diplome":"xcv","entretien_le":"2018-11-10","commentaire":"xv","etat":"ne correspond pas","retour":"Proposition de poste","meta":{"revision":0,"created":1542277701035,"version":0},"$loki":1},"idIndex":[1,2,3,4,5,6,7,8],"binaryIndices":{},"constraints":null,"uniqueNames":["id"],"transforms":{},"objType":"candidats","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"ttl":null,"maxId":8,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[]}],"databaseVersion":1.5,"engineVersion":1.5,"autosave":true,"autosaveInterval":5000,"autosaveHandle":null,"throttledSaves":true,"options":{"autoload":true,"autosave":true,"autosaveInterval":5000,"serializationMethod":"normal","destructureDelimiter":"$<\n","recursiveWait":true,"recursiveWaitLimit":false,"recursiveWaitLimitDuration":2000,"started":1542280250791},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"}'''
here is the json database file that I get from lokijs I parse it before integrating it into datatables into an array objectc (object0, object1, etc ..) lokijs uses an id of its own $ lokijs1 $ lokijs2 my console after the parsage of my json m well displays my table but datatables do not want
Ok, Please post an example of the parsed data and your Datatables init code. Also post any alert messages or console message you receive.
Kevin
here is an example of my code with the log the invalid error message json so i understand that he can not read it
https://gyazo.com/25c31ce4f41d41868ae26994ea0762b3
The invalid json message is probably due to the incorrect use of the
ajax
option. It does expect a URL to fetch the data.My suggestion would be to remove the Datatables ajax config. Then in your
readTextFile
function userows.add()
anddraw()
to populate the table. Where you haveconsole.log(test)
; try the followingtable_companies.rows.add( test ).draw();
.Not sure if your data structure matches the
columns.data
config but it should work if they match. When you are initializing Datatables you have lower cased
fordataTable()
. You will want to change it to upper case like this:DataTable({ ... });
to get the API. See this FAQ:https://datatables.net/faqs/index#api
Kevin
great
we made a lot of progress here so I go with another error tn / 4 error table id unknows parametre..normal since there is no id but the lokijs parameter for id is $ lokijs: 1, $ lokijs2, etc ...
You didn't post the actual data structure for each row so I'm not sure. Did you follow the troubleshooting steps in the link provided in the error?
https://datatables.net/manual/tech-notes/4
Basically your data structure doesn't match what you defined in the
columns
option.Kevin
Can you show the full error message please?
Allan
ok here console log:
https://gyazo.com/3e67fd780f51b7e25a7e864f2b9f948a
my html code:
https://gyazo.com/3ec3746981518401d73c20074df6304a
error message:
https://gyazo.com/7d6d7b797b643669511d3e8165e423e1
It looks like your first two elements (rows) have different objects than the remaining rows. The error states that its looking for the property
nom
which doesn't appear to exists in the first row. Maybe you can eliminate the first two rows from your data?Kevin
i create new json file here
https://petit-fichier.fr/2018/11/16/objet/
look this log name is ok
https://gyazo.com/6ad19a911e1ed63f83dc6ca7e4e6e8c6
I have to miss something but I do not know what
thank for your big help
I'm unable to open the first link. But comparing your array of objects to the original screenshot of the Datatables config there are some differences.
In Datatables you defined a
functions
column which isn't in your data. Also I the property names might be case sensitive so you need to fixEntree_le
andcommentaire
. Both data structures need to match.As a side note it would be easier if you copied the text into the thread instead of using screenshots.
Kevin
I pasted some of the code here
https://codepen.io/tycoons/pen/MzvaLb
i try to change
The code doesn't seem to run. But I do see one issue. You have this:
When I suggested removing the
ajax
I meant for you to remove all the options within which were 'type', 'data', 'dataType'.I made the other two changes I suggested:
https://codepen.io/anon/pen/RqZaVK
Try that and let us know.
Kevin
Hi Kevin,
I applied the patches and modify the fields to avoid being sensitive to the box but this shot so I have an error message different
No data available in table and this error
Uncaught TypeError: table_companies.rows(...).add is not a function
Sorry, incorrect syntax on my part. You want to use
rows.add()
so it looks like this:table_companies.rows.add( test ).draw();
Note the removed
()
after rows.Kevin
nice very good thank for your help i modifie lokijs for disable meta array
i work fine thank you very weel my friend