Adding a new row
Adding a new row
peterkronenberg
Posts: 112Questions: 0Answers: 0
I know that fnAddData() or fnAddDataAndDisplay() can be used to insert new data to the table, but I'm trying to figure out the best interface for the user. I want to do something like open a row and display empty fields that the user can fill in. Once I have the data, I can call fnAddData() to add it properly (and possibly sort it).
But I don't want to open the last row on the screen. I would rather have it be the first row on the screen. I.e., after the last row on the previous page (or the very first row, if on the first page).
How can I figure out what row is on the top of the page (i.e., an index)? I could then use fnDisplayStart to move the previous row to the top of the screen and then do an fnOpen() on that.
Is there any other way to open up a skeleton row?
Any thoughts?
But I don't want to open the last row on the screen. I would rather have it be the first row on the screen. I.e., after the last row on the previous page (or the very first row, if on the first page).
How can I figure out what row is on the top of the page (i.e., an index)? I could then use fnDisplayStart to move the previous row to the top of the screen and then do an fnOpen() on that.
Is there any other way to open up a skeleton row?
Any thoughts?
This discussion has been closed.
Replies
However, I'm thinking that you want to insert a row at the very top of the table - is that right? That's not something fnOpen will do - it will always open a row just under the parent. What you could do is insert a TR element manually and that will do the job fine (a bit like what fnOpen does). It would be lost on any redraw, unless you take steps to prevent that, but it's one option. Personally I quite using a lightbox for a CRUD style interface with DataTables.
Allan
I have no problem having fnOpen open the row after the parent. But I want the parent to be the last row on the previous page.
But I like the idea of inserting a TR manually. I wasn't sure if that would cause any problems. That's actually perfect behavior if it will be lost on the redraw as I'll do the redraw as soon as I call fnAddData.
When you say that you use a lightbox, you mean that you use pop up a dialog? I thought of that, but for some reason, didn't like the idea. One thing that I didn't like about lightbox is that it's not draggable. The user might want to enter new data by looking at some of the existing data.
Do you have any examples?
It doesn't work quite like this - if you fnOpen the last row in a page, it will still be shown on that page - not on the next one (as can be seen in this example: http://datatables.net/examples/api/row_details.html ).
> Lightbox
> Do you have any examples?
Not any which are publicly available I'm afraid. Whether it is suitable or not for a project depends on the UI that you intend to create. Typically I've used Fancybox ( http://fancybox.net/ ) and that's been working well for me, although I have also done something a bit like you are intending (available not public code I'm afraid) and that also works well in that setting. It just depends on what you want to create :-)
Allan