1

In my grid, created with slick grid I am trying to create grid row .It is possible to get a unique ID only after saving these row data to the back-end database. How can I handle this situation? Without unique id, the cell data is not retained there when I move to next cell

Geo V L
  • 866
  • 8
  • 25

2 Answers2

0

I would do this method:

  1. Create a temporary unique_id for the new row data.
  2. Post the row data to back-end database and return the id generated on callback.
  3. Update the row data with the returned id that was generated.
winghei
  • 632
  • 4
  • 9
0

An alternative and probably faster (in terms of saving a network round trip) solution is that you generate a GUID/UUID on client side. To back off generating GUID with example JavaScript code, check out this great SO answer.

Quote about the collision probability when generating GUID:

For example, with 3.26x1015 version 4 RFC4122 UUIDs you have a 1-in-a-million chance of collision.

And the quoted code you can generate a GUID with:

'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
    return v.toString(16);
});

results in:

"3bce4931-6c75-41ab-afe0-2ec108a30860"

So the actual steps of execution I propose are:

  1. Generate your cell data
  2. Generate the GUID

Voila, you have your unique ID and can move the next cell, row, etc.

Community
  • 1
  • 1
kayess
  • 3,384
  • 9
  • 28
  • 45