Datatable similar to .NET datagridview
Datatable similar to .NET datagridview
Hi all,
Unusual question. I hope someone can assist.
I am trying to decide how best to use Datatables (the Editor specifically) with inline editing. In VB.NET I can create a datagridview. I can add, remove and update all within that datagridview. Then, when I want to send the data to SQL, I can do it in bulk (using bulkcopy) or iterating through the records to inject the data row by row,into a SQL table.
I want to do something similar with Datatables and/or the Editor.
What I want to do but don't know if it is possible:
1) Start with empty Editor
2) Using an "Add" button, add a blank row (or have the editor come up with a new row (row 1) with empty cells
3) Using inline editing, the user modifies all the columns they need
4) When the user types in any of the initial fields on row 1, a new second row, is created, empty and waiting on input
5) Repeat until all data is entered for 1, 2, 10 or 20 rows
6) Upload all data from table to SQL via AJAX (this is the only time AJAX is called/used)
Is this something that can be done with the Editor?
Kind Regards,
Jason
This question has an accepted answers - jump to answer
Answers
Yes - that can be done. It will need some use of the API since it doesn't work that way out of the box, but what I would suggest is that you need a local editing table and call the
create()
method to create a new row (submit immediately by callingsubmit()
so there is an empty row in the table). Then use inline editing as normal.You can add another row to the table at any time by calling
create()
andsubmit()
again.Finally use
rows().data()
to get the data from the table and you can then Ajax submit that to the server.Allan
Hi Allan!
Thank you for the quick response. I will work with your suggestion and everyone know how it goes!
Regards,
Jason
Hi Allan,
Well I was able to get it working (more or less!). Currently, when I move from the dropdown column to another column, the value reverts back to default. All other columns work properly that do not have the dropdown.
Additionally, when I select "New" and fill out the form, the dropdown populates in the form, but I get the error :
Datatables warning: table id=example - Requested unknown parameter 'material.name' for row 3, column 3. For more information about this error, please see http://datatables.net/tn/4
Here is my JSON:
Here is my Editor javascript code:
I have been working on this since yesterday and cannot seem to get past this issue. I know I am just missing something simple, but my eyes are glazing over.
I have more! So I was able to cut down on my JSON to just the basics, I am now populating the dropdown and it is keeping the data when I move to another column, however it is not choosing the label, it is choosing the value when it does.
I'll continue working on this tonight.
There is no
mats
data point in your JSON data, so no value can be populated into it. It looks like you actually want to usematerial.id
but you'd need to add theid
(or whatever that column is called) into yourmaterial
object. Its missing that bit of information at the moment.Allan
If you don't mind, could you please clarify your previous message? I trimmed down the code a bit below and everything is working except it is displaying the value instead of the label when calling the submit on cell transition:
Code:
JSON
Hi again Allan,
I am not sure if this is the best way to do this. I created a dataSrc object (optlist) of the options list. In the render for the column I parsed that object and found a match for the column data. Then return the .label from the object.
The object creation for "whatever"
The column render
Don't you need to return something in the event that optlist.materials[i].value != data ?
Ah good point tangerine, I would just return (data) at that point.
The looks like a good workaround - nice one.
Allan
good afternoon can someone please pass me an example of a table on vb.net please thank you very much greetings