tabalinas / jsgrid

Lightweight Grid jQuery Plugin
http://js-grid.com
MIT License
1.53k stars 353 forks source link

event on cell value change #1409

Closed sjeffblack99 closed 2 years ago

sjeffblack99 commented 2 years ago

I'm new to JSGrid and I'm looking for a way to update two cells in my grid immediately after the value of another cell is changed. It appears that there are numerous events that fire before or after the entire row is edited (onItemEditing, onItemInserting, onItemInserted, onItemUpdating, onItemUpdated), but I don't see any events that fire when one particular cell is updated.

My scenario is as follows. I have columns for SSN, Last Name, First Name, and some other cells related to the person. Once the user enters an SSN, I need to see if the SSN already exists in the database. If so, I need to populate the first and last names so the user doesn't have to type them again. Then they can move onto editing the rest of the columns. If the person doesn't exist in the database, the first/last names should remain blank so that the user can enter this information, thereby adding a new person to the system.

So what I really need is an "onCellUpdated" event. This would allow me to make the ajax call after SSN is entered and check to see if the person exists in the database, and then presumably fill the first/last name columns automatically.

I saw another similar post (https://github.com/tabalinas/jsgrid/issues/898), but this request doesn't seem to require an event after a cell update.

Any help is greatly appreciated.

Thanks.

sjeffblack99 commented 2 years ago

To add to my previous request, I was able to get an event to fire upon update of the SSN cell by adding the following:

editTemplate: function (value, item) {
     return $("<input type='text' value='" + value + "' onchange='fnSSNChange(this, " + item.rowid + ");' />");
},
insertTemplate: function () {
     return $("<input type='text' onchange='fnSSNChange(this, 0);' />");
},

Function fnSSNChange is being fired correctly on the change of an SSN. I can now call an ajax method to get my first name and last name. However, I'm not sure how to go about actually updating the last name and first name textboxes on the row being edited.

Any ideas?

Thanks again.