Add New, Edit, Delete Buttons
Add New, Edit, Delete Buttons
xtremer360
Posts: 84Questions: 2Answers: 0
I keep seeing these buttons on some of the examples for the datatables that will bring up forms for the add new and edit buttons and then delete the row after sending data about the row to the server. However I'm having a hard time finding how to add these to the sDom.
This discussion has been closed.
Replies
A typical initialisation to get the buttons might look like this:
[code]
$('#example').dataTable( {
"sDom": "Tfrtip",
"sAjaxSource": "php/browsers.php",
"aoColumns": [
{ "mDataProp": "browser" },
{ "mDataProp": "engine" },
{ "mDataProp": "platform" },
{ "mDataProp": "version", "sClass": "center" },
{ "mDataProp": "grade", "sClass": "center" }
],
"oTableTools": {
"sRowSelect": "multi",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
} );
[/code]
(from http://editor.datatables.net/release/DataTables/extras/Editor/examples/index.html ).
Worth noting that the buttons can be completely customised to perform whatever actions you want :-)
Allan
[code]
$( '#titlestatuses-table' ).dataTable({
"sDom": '<"top"lf<"clear">>rt<"actions"<"actions-left"i><"actions-right"p>>',
"bAutoWidth": false,
"sAjaxSource": "php/titlestatuses.php",
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 0 ] },
{ "sWidth": "20px", "aTargets": [ 0 ] },
{ "sWidth": "40px", "aTargets": [ 1 ] },
{ "sClass": "alignCenter", "aTargets": [ 1 ] }
],
"oTableTools": {
"sRowSelect": "multi",
"aButtons": [
{ "sExtends": "editor_create", "editor": editor },
{ "sExtends": "editor_edit", "editor": editor },
{ "sExtends": "editor_remove", "editor": editor }
]
}
});
[/code]
The old code that did work was this:
[code]
$( '#titlestatuses-table' ).dataTable({
"bAutoWidth": false,
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [ 0 ] },
{ "sWidth": "20px", "aTargets": [ 0 ] },
{ "sWidth": "40px", "aTargets": [ 1 ] },
{ "sClass": "alignCenter", "aTargets": [ 1 ] }
]
});
[/code]
Allan
http://www.kansasoutlawwrestling.com/kowmanager/titles/titlestatuses
Yes Editor is commercial software an requires a license ( http://editor.datatables.net/purchase/ ). As you say, money is tight, and we all have to earn some somehow :-).
> is there an alternative way of creating these add/edit/delete buttons and still keep similar functionality??
TableTools is open source (GPLv2 or BSD) and that is what is being used to actually create those buttons - so you could do that, and the create software such as Editor that will actually do something when you click on the buttons. Editor is really designed to be a 'time saver' so you can just pick it up without needed to write a whole lot of editing software, leaving more time for earning cash :-)
Allan
http://www.kansasoutlawwrestling.com/kowmanager/titles/titlestatuses
Allan
Allan
[code]
{
"sExtends": "text",
"sButtonText": "Delete",
"sButtonClass": "delete",
"sAjaxSource" : "/path/to/function",
"fnServerParams": function (aoData) {
aoData.Push(ArrayWithCheckboxInfo);
},
"fnClick": function ( nButton, oConfig, oFlash ) {
alert( 'Mouse click' );
}
},
[/code]
Here's my table:
[code]
IDTitle NameStyleStatus
1Undisputed TitleSinglesActive
2Outlaw TitleSinglesActive
3Tag Team TitlesTag TeamActive
4asdfSinglesInactive
5Testing TitleStableActive
6Testing TitleTag TeamInactive
7testingSinglesActive
[/code]
Basically you just need to make a plain old $.ajax() call inside fnClick :-). See:
http://api.jquery.com/jQuery.ajax/
Allan