Skip to content
Advertisement

Datatables CRUD operations

I am developing a tasking application that tracks tasks with various metadata for the tasks. When the task is created, the options are saved to a related list. However, the metadata tags may change as the task progresses. I am using DataTables to display the options. The below code loads in the full list of options, then the selected entries, and combines into an array to track changes. As buttons are pressed for primary or secondary, the array is updated for the appropriate action to the item, i.e. if it’s new, flag for create. If it has a list ID number, flag for update, and lastly mark any that have a listID but are not selected for delete. My prototype is working but I do not think I did it in an efficient manner and I am concerned that it will not scale well if I add a 3rd button for tertiary selection. The nested if statement are already getting crazy.

Right now, it is intended that selecting a new primary will clear out any existing secondary selections.

JavaScript

http://live.datatables.net/salohoro/1/ is a working copy as well. Any advice on efficiency and scalability would be appreciated.

Advertisement

Answer

some very minor tweaks,

I changed

JavaScript

to

JavaScript

to reduce the number of times you need to check for !== ‘Primary’

I changed “=” to “===” and “!=” to “!==” as that’s better practice to ensure exact matches and changed vars to let and const to ensure better data type consistency

As for the for loops they actually perform better as is, see this comparison of loop types and their respective performance results: https://github.com/dg92/Performance-Analysis-JS

The rest of it looks find, if you find scaling it up you hit performance issues then maybe refactor out some of the logic into individual functions that you can call with Web Workers, they will really help improve performance, see https://medium.com/jspoint/achieving-parallelism-in-javascript-using-web-workers-8f921f2d26db

JavaScript

I hope this helps

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement