Dear team i am new in using datatable i have a datatable where i want to add a textbox for each row and on button click event i want to save it in the db with respective textbox to its particular id
````
````
this is my datatable
i am struck after this part any help will be appreciated
Tuhin PaulPosted Apr 24, 2023, 3:42 AM
To save the data in the database with the respective textbox, you need to handle the button click event and retrieve the data from each textbox using their respective `id`s.
Here, you are handling the `click` event of a button with the `id` "btnSave". Inside the function, you are iterating over each row of the datatable and retrieving the values of the checkbox and the textbox using their respective `name`s. You are then creating an array of objects with the `employeeInsuranceId` and the `nomineeName` for each row. You are sending the data to the server using an AJAX call to a URL `/HRValidation/SaveInsuranceNominee`. You are also setting the `contentType` to `"application/json; charset=utf-8"` to indicate that you are sending JSON data in the request body.
You will need to modify the server-side code to handle the data sent from the client and save it in the database with the respective `employeeInsuranceId`.
kaushik guruPosted Apr 25, 2023, 8:52 AM
@tuhin paul the array object is alwasy returning null
This is my controller
and this is my model
what am i doing wrong here ?
Tuhin PaulPosted Apr 24, 2023, 3:41 AM
To add a textbox for each row of your datatable, you can add another column in your `columns` array and use the `render` function to return a textbox with a unique `id` for each row.
The new column will have a `render` function that returns a textbox with a unique `id` for each row. The `id` is generated by concatenating the string `"txtNominee_"` with the `employeeInsuranceId`.
Naimish MakwanaPosted Apr 24, 2023, 3:39 AM
To add a textbox for each row in your datatable, you can modify the
columnsarray in your datatable initialization code. You can add a new column to thecolumnsarray and use therenderfunction to generate the textbox HTML for each row. Here's an example:This adds a new column to the datatable with a textbox for each row. The
nameandidattributes of the textbox are generated using theemployeeInsuranceIdfield, so each textbox will have a unique identifier.To save the textbox values to the database when a button is clicked, you can loop through the rows of the datatable and retrieve the value of each textbox. You can use the
rows()anddata()methods of the datatable object to get an array of all the rows and their data, and then loop through the array to get the textbox values. Here's an example:Thanks