How to display seleceted table row/column data in remove confirmation message

How to display seleceted table row/column data in remove confirmation message

Tony_BartolucciTony_Bartolucci Posts: 2Questions: 1Answers: 0
edited March 2015 in Editor

Am using datatable editor

   $(document).ready(function () {
                
                 editor = new $.fn.dataTable.Editor( {
                        "ajax": {
                             edit: {
                                 type: 'POST',
                                 url:  '${contextPath}/updateUser'
                             },
                             remove: {
                                 type: 'POST',
                                 url:  '${contextPath}/deleteUser'
                             }
                        },
                        i18n: {
                            remove: {
                                confirm: {
                                    1: "Confirm deletion of record."+'${contextPath}'+delName
                                }
                            }
                        },
                        "table": "#example",
  } );

And datatable with table tools

   tableTools: {
                        sRowSelect: "os",
                        aButtons: [
                            { sExtends: "editor_edit",   editor: editor },
                            { sExtends: "editor_remove", editor: editor }
                        ]
                    },

And used

 editor
                    .on( 'initRemove', function ( e, data, action ) {
                      var oTT = TableTools.fnGetInstance( 'example' );
                      var aData = oTT.fnGetSelectedData();
                      delName=aData[0].userName;
                      alert("a ="+delName);
                   } )

how to display userName info in delete confirmation meassage?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    edited March 2015 Answer ✓

    Hi Tony,

    It looks like you are on the correct path with initRemove and accessing the selected data. The one missing step is to use message() to display the message e.g. you might have the following where you currently have the alert():

    editor.message( "Are you sure you wish to delete the user "+delName );
    

    If you'd like to refine it further you can use the data parameter being passed into initRemove rather than needing to use the rather messy TableTools API (I'm going to be replacing it soon!):

                   editor
                       .on( 'initRemove', function ( e, node, data ) {
                         editor.message( "Are you sure you wish to delete the user "+data[0].userName );
                      } )
    

    Note the use of the array index [0] - this is because remove() can be called on multiple rows.

    Regards,
    Allan

  • Tony_BartolucciTony_Bartolucci Posts: 2Questions: 1Answers: 0

    Thanks a lot Allan. It worked perfectly :)

This discussion has been closed.