JsGrid - Auto Increment ID - javascript

I recently started using JsGrid and I really like it. It is simple to interact with and well documented.
I though face a small issue:
Whenever I insert a new row in the JsGrid application I get asked an ID. If this ID happens to be the same as an already existing ID, it will give my an error on my MySql database (unique key).
Is there a way to fill in the ID for the user and make sure he can not alter it while inserting?
Thanks!

Usually ID is generated on the DB level. So user should not provide the ID for new items. Remove ID field from the grid or just make it readonly, removing the type attribute.
It's implemented in the sample project, showing how to use jsGrid with PHP + MySQL RESTful backend https://github.com/tabalinas/jsgrid-php.

Related

How to save report filters and making it available for executing and scheduling

I have a use case where I have to Add query params to APIs call, and save it accordingly.
Meaning- I have one report to Add, which gives multiple filters that to be saved. (Some of them are pre-defined and others can be added) which could be saved and it could run to generate report or to schedule it.
How here I am using postgres sql as DB. How can I solve such scenarios, If say saving into db then what's the best way to do such operations? I have a db table where I am storing Report name and descriptions. But how can I add such Filters and Save it? And next time the user just Schedule or generate report with saved filters.
Below are the images for better understanding of the scenario.
The Image of where List displayed of saved reports
The Image where user can Add custom report using available filters.
Not sure the best way to handle such scenarios, where I have to add multiple of filters and save it accordingly.
Can anyone help me here with the approach to handle such things? Like saving in DB or how it could work the best.
Thanks
Edit- Something like JIRA, can save the filters and directly apply it. Something like this.
Assuming that you have control over your web application and that it will translate what users input into SQL queries, just create a data structure that both your UI and your data tier can understand and store it in a table using the JSON or JSONB datatype.

TODO-list: How to add items on the list immediately, before server responded?

I'm creating a TODO-list using React.
When the user fills all the fields and presses the ADD button, I want immediately add the item to the list, and then send this item to the server. Then, the server responses with the ID of this item in the database.
The problem is that my app uses item IDs to remember which items are selected at the moment. Also, I want to use IDs in the browser's address bar. But the item ID is being generated on the server, so I cannot figure it out before server responded.
What options do I have?
You can easily add items to a react list without relying on the server-side ID.
If you really need the ID generated by the back-end, I don't think this is possible.
You could of course use some temporary front-end ID (e.g. based on an educated guess) and replace that with the actual ID once the back-end responded, but that would obviously require some obscure bookkeeping and mapping.
It also depends on the way your ID's work. If an item-ID is a combination of the user and the item, the above should be feasible.
Im not sure we are on the same page but u can use local storage to save data and do your local stuff before server response

Edit in Ember with Ember data an object and its sub-collection in one form

I am working on an application with Ember + Ember Data.
I have a model "Tax" with a collection of "Sub-Regions".
I also created a list of tax objects, with an Edit button. When a user goes to edit, I have created a form, that has fields for the properties of Tax, as well as a list of Subregions with a text input field to modify the default tax rate for the subregion. What I would like to do is to be able to save in one action the object Tax and all the items of the sub-collection. I'm stuck creating that action, not sure how to approach that problem.
I've put a sample here: http://emberjs.jsbin.com/jinovi/6/
I come from a back-end background and I know how I would solve it using MVC with page refresh, but not sure how to do it in Ember.
I've noticed that it gets all saved locally because I'm using Fixtures, I guess that if I use the REST adapter it will work in the server too.
I've put a sample here: http://jsbin.com/jinovi/8/

Spring MVC Ajax Request to Refresh Dynamic Table

I currently have a spring mvc app that gets a list of users from a database and displays their information in a table using JSP to basically loop through each object in the list and create a table row for them.
Each user has an expiry date attribute as part of their record in the database. What I want to achieve is basically a button that when toggled shows or hides all users that have expired (i.e. their expiry date is less than today's date).
For this I am trying to use AJAX calls to my controller to fetch me all users expired or not OR only users that haven't expired depending on how the button is toggled.
What I would like help on is the best way to achieve this as I can think of a few nasty ways of doing it like having a separate page and refreshing but I am confused on a few things.
Should I just ditch the JSP looping through to make the table and make a method in JavaScript that creates that table when given the data? If so how do I get the data from the controller to JavaScript, can an AJAX call to a controller return me a list of my user objects?
My best guess is that instead of adding a list of objects to a model and letting JSP do the work, that I instead return a JSON with the data and use JavaScript to build the table. I can then call an update method to re-build the table.
You are correct. You have 2 options:
Have AJAX call return html (i.e. jsp) for the table and then replace
the body of the table
Use JavaScript to build the table and then
update the table with AJAX call which returns JSON.
If you want to get more sophisticated, you could use a JavaScript framework like Knockout.js which would let you mark up the table and refresh the table without too much of JavaScript writing.
Blurgh I'm not sure why this question has received so much attention, especially now in the days of angular but if you are struggling with this then I would strongly recommend the following library:
https://www.ag-grid.com/

How to work around missing insertId in WebSQL

I want to obtain the ID of the just inserted record into a WebSQL database. WebSQL has the InsertID Property for this task.
However this property is not supported in the Cordova WebSQL Plugin.
The Cordova WebSQL Plugin adds WebSQL to Windows8 Cordova Apps
https://github.com/msopentech/cordova-plugin-websql/
This plugin however doesn't support the insertId Property - see quirks section
How to efficiently obtain the ID of a newly inserted record without using the insertId?
I am suggesting a workaround for SQLITE db and assuming that the implementation of WebSQL is similar to SQLLite db.
I feel that you would at least have to make two passes (two SQL) statements for getting the last insert ID. The easiest option is trying to get the maximum id that has been inserted in the table e.g if id is the column set to autoincrement then use the below sql.
select max(id) from table
and then using the max(id)+1 from above as the insertId that would get inserted into the table.
2nd Option:
In SQLite when you create a table with an autoincrement column an entry is made in the sqlite_sequence table. It holds the value of the last id that has been applied to the column. You need to select the id for the table as shown below.
You need to find out what is a similar table WebSQL.
select seq from sqlite_sequence where table = <table_name>
Increment the seq from above query to 1 to get the sequence that will be used by the autoincrement for the desired table as the last insertId.

Categories

Resources