This is a migrated thread and some comments may be shown as answers.

Delete confirmation message that contains information from row's model

3 Answers 1469 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 24 May 2012, 02:38 PM
Grid configuration properties allows for only a static text message.  The default is 
DELETECONFIRM = "Are you sure you want to delete this record?",

I typically like to include teaser information in case the user isn't paying attention or stray clicked.  For example:
"Are you sure you want to delete Jim Bob's dental records?",

Such a message requires Grid _confirmation method to handle a confirmation setting which is a function.  The following code modifications does so:
grid.js
removeRow calls _confirmation with model
removeRow: function(row) {
     var that = this,
         model,
         mode;
  
     row = $(row); //RAD
     model = that._modelForContainer(row); // RAD
  
     // if (!that._confirmation()) {
     if (!that._confirmation(model)) { // RAD pass model unconditionally.  callee will decide what to do with it
         return;
     }
  
     row.hide();
     // row = $(row).hide(); // RAD
     // model = that._modelForContainer(row); // RAD
  
     if (model && !that.trigger(REMOVE, { row: row, model: model })) {
         that.dataSource.remove(model);
  
         mode = that._editMode();
  
         if (mode === "inline" || mode === "popup") {
             that.dataSource.sync();
         }
     }
 },

if confirmation is a function pass the model to it
_confirmation: function(model) { // RAD
    var that = this,
        editable = that.options.editable,
        confirmation = editable === true || typeof editable === STRING ? DELETECONFIRM : isFunction(editable.confirmation) ? editable.confirmation(model) : editable.confirmation;
  
    return confirmation !== false && confirmation != null ? that._showMessage(confirmation) : true;
},

mypage.js
and in .kendoGrid configuration specify confirmation as a function.
editable: {
    mode:"popup",
    confirmation: function(model) {
        return 'Are you sure you want to delete the '+model.rectype+' record of '+model.name+'?'
    }},

A coder could also template the confirmation text, but only the text because the confirmation dialog raised by _showMessage is the native browser routine window.confirm(text).

A further modification of _confirmation could handle the return type to enable an even more sophisticated custom confirmation() behavior: 
string -> use standard kendo prompter with returned text as prompt
false -> cancel the delete action. function raised a custom dialog, or programmatic determination
true -> attempted an unprompted deletion.  function raised a custom dialog, or programmatic determination

Enjoy,
Richard

3 Answers, 1 is accepted

Sort by
0
Steve
Top achievements
Rank 1
answered on 28 May 2012, 02:36 PM
hi - newbie here...what is the easiest way to suppress the delete confirmation alert box altogether? thanks!
0
Richard
Top achievements
Rank 1
answered on 28 May 2012, 04:12 PM
use confirmation:false to bypass the confirmation dialog

    editable:{confirmation:false} 

See 
http://jsfiddle.net/RichardAD/aNCV4/ 
0
Steve
Top achievements
Rank 1
answered on 28 May 2012, 05:05 PM
thanks so much for the help Richard, that does it!
Tags
Grid
Asked by
Richard
Top achievements
Rank 1
Answers by
Steve
Top achievements
Rank 1
Richard
Top achievements
Rank 1
Share this question
or