jquery-tabledit icon indicating copy to clipboard operation
jquery-tabledit copied to clipboard

add new row

Open roydekleijn opened this issue 8 years ago • 23 comments

Nice feature will be to be able to add a new row/record .

Please let me know how I can help you on this

roydekleijn avatar Apr 01 '16 20:04 roydekleijn

I want that too. This is how I did for now.

Assuming the table is: <table class="table table-striped table-bordered" id="example5"> <thead> <tr> <th>#</th> <th>Nickname</th> <th>Firstname</th> <th>Lastname</th> </thead> <tbody> <tr data-id="1"> <td class="tabledit-data">1</td> <td class="tabledit-data">markcell</td> <td class="tabledit-data">Celso</td> <td class="tabledit-data">Marques</td> </tr> <tr data-id="2"> <td class="tabledit-data">2</td> <td class="tabledit-data">dotz</td> <td class="tabledit-data">Márcio</td> <td class="tabledit-data">Quental</td> </tr> <tr data-id="3"> <td class="tabledit-data">3</td> <td class="tabledit-data">zikospeed</td> <td class="tabledit-data">António</td> <td class="tabledit-data">Figueiredo</td> </tr> </tbody> </table>

I added a button <button id="addRow">Add Row</button>

And then add the new row with: $("#addRow").click(function() { var tableditTableName = '#example5'; var newID = parseInt($(tableditTableName + " tr:last").attr("data-id")) + 1; var clone = $("table tr:last").clone(); $(".tabledit-data span", clone).text(""); $(".tabledit-data input", clone).val(""); clone.appendTo("table"); $(tableditTableName + " tr:last").attr("data-id", newID); $(tableditTableName + " tr:last td .tabledit-span.tabledit-identifier").text(newID); $(tableditTableName + " tr:last td .tabledit-input.tabledit-identifier").val(newID); });

Apologies for the formatting - this is my first post on GitHub and I don't know what I'm doing wrong!

warrenAR avatar Apr 22 '16 07:04 warrenAR

Wow .. perfect, it's works like a charm!. Thank you for this

klaujesi avatar Jul 27 '16 02:07 klaujesi

Hi @klaujesi , I have a question. How can I make the newly added record under edit status?

jianyuanzh avatar Sep 20 '16 03:09 jianyuanzh

Hi, i did some modifications for @warrenAR code for current version of jquery-tabledit:

$("#button_add_row").click(function() { 
	var tableditTableName = '#example1';  // Identifier of table
	var newID = parseInt($(tableditTableName + " tr:last").attr("id")) + 1; 
	var clone = $("table tr:last").clone(); 
	$(".tabledit-span", clone).text(""); 
	$(".tabledit-input", clone).val(""); 
	clone.prependTo("table"); 
	$(tableditTableName + " tbody tr:first").attr("id", newID); 
	$(tableditTableName + " tbody tr:first td .tabledit-span.tabledit-identifier").text(newID); 
	$(tableditTableName + " tbody tr:first td .tabledit-input.tabledit-identifier").val(newID); 
	$(tableditTableName + " tbody tr:first td:last .tabledit-edit-button").trigger("click"); 
});

Note the last line force to show in edit mode.

romanribes avatar Dec 29 '17 09:12 romanribes

Can someone tell me, how to insert my "new row data" to the database ?

rcrdo520 avatar Aug 15 '18 13:08 rcrdo520

I just made a few changes to implement add button, https://pastebin.com/nQ1FUgfk

cahpalencia avatar Aug 17 '18 14:08 cahpalencia

@cahpalencia Thank you so much! Finally i was able to extend the example.php with an add button. My Example.php:

https://pastebin.com/PGCsfgwH

rcrdo520 avatar Aug 17 '18 17:08 rcrdo520

@cahpalencia Thank you but is there a way I can just move the button to be under the table?

jonetiz avatar Feb 11 '19 08:02 jonetiz

Thanks for the version with the add function. However when I attempt to use it for some reason the edit is now sending an add action upon save vs the non-modified script that sends an edit action. Does anyone know the best way to resolve this without potentially breaking other functionality?

jonfranz24 avatar Feb 20 '19 06:02 jonfranz24

@cahpalencia Thank you so much! Finally i was able to extend the example.php with an add button. My Example.php:

https://pastebin.com/PGCsfgwH

I tried using it but I was unable to work. It did not show an add button. any help towards resolving it would be appreciated

dwhyte4 avatar Mar 07 '19 01:03 dwhyte4

Contributions.zip that is my file

dwhyte4 avatar Mar 07 '19 01:03 dwhyte4

I just made a few changes to implement add button, https://pastebin.com/nQ1FUgfk

I am actively optimizing your file @cahpalencia. I have resolved some issues described above. When I have the time, I will fork this repo and update it. Cheers. @jonfranz24 @jonnyetiz

ABCarnage avatar Apr 08 '19 12:04 ABCarnage

I just made a few changes to implement add button, https://pastebin.com/nQ1FUgfk

I am actively optimizing your file @cahpalencia. I have resolved some issues described above. When I have the time, I will fork this repo and update it. Cheers. @jonfranz24 @jonnyetiz

@ABCarnage Im waiting for the solution about the reply of @jonnyetiz

luisestebancastillo avatar Apr 16 '19 17:04 luisestebancastillo

Any update ? If help is needed I'm available.

PicchiKevin avatar Jun 13 '19 23:06 PicchiKevin

Thanks for the version with the add function. However when I attempt to use it for some reason the edit is now sending an add action upon save vs the non-modified script that sends an edit action. Does anyone know the best way to resolve this without potentially breaking other functionality?

This is not a final version, its just an idea, Edit and Add send edit action so I validate if the id exists.

cahpalencia avatar Jun 14 '19 20:06 cahpalencia

@rcrdo520 I know you were working on this a while ago but how did you get the 'action' to equal 'add'? I implemented all the code but when I click the add button and fill out the row data, developer tools shows that 'action' is being set to 'edit' and in turn won't run my php/sql command.

any advice would be great! thanks!

Brian-Salvati avatar Dec 03 '19 20:12 Brian-Salvati

Good news, I am finally working on it. I am in the process of simplifiying it (a version I made for a project with some extra features) and making an example page for it; I added a add row button, works with bootstrap 4 and font awesome .... Follow my fork for an update in the next following days. In v2-dev branch, I guess: https://github.com/ABCarnage/jquery-tabledit/tree/v2-dev

ABCarnage avatar Dec 11 '19 15:12 ABCarnage

See here, my edit for add-button. Use a PHP server to it. Commit: https://github.com/ABCarnage/jquery-tabledit/commit/e958873035b3a91f5fc65eb03bb6b372b484b8ff

ABCarnage avatar Dec 17 '19 19:12 ABCarnage

@ABCarnage In looking at your v2 version, I am trying to see how it matches the original version. You don't have any calls to a db connection, and I don't see where it's obvious file changes/naming. Do you think you can assist me with this?

jmwebguy avatar Mar 26 '20 18:03 jmwebguy

See here, my edit for add-button. Use a PHP server to it. Commit: ABCarnage@e958873

Can you send php example. I have a problem with recognizing the ID

brajbaj avatar Jul 09 '20 07:07 brajbaj

hello,

in line 452: $(td).find('.tabledit-delete-button').addClass('active');

should it be

$(td).find('.tabledit-confirm-button').addClass('active');

?

mquevedob avatar Oct 27 '21 10:10 mquevedob

also, in line 443: $(td).parent('tr').remove();

I think it should not be removed yet, since there can be an error from the php script

mquevedob avatar Oct 27 '21 11:10 mquevedob

same goes for line 280

this whole section should be called in the ajax function

$(td).each(function() { // Get input element. var $input = $(this).find('.tabledit-input'); // Set span text with input/select new value. if ($input.is('select')) { $(this).find('.tabledit-span').text($input.find('option:selected').text()); } else { $(this).find('.tabledit-span').text($input.val()); } // Change to view mode. Mode.view(this); });

mquevedob avatar Oct 27 '21 14:10 mquevedob