Delete Confirmation and Grid Length

Mar 27, 2010 at 12:28 PM

1st of all, MVC Crud works great!

I've been working wih it for a while now building a small test application in hopes of using it for a more substantial application down the road.  I'm using the sample application for reference.  And I'm new to jqGrid.   I've got a couple of questions.

1. I'm using the out-of-the box delete row capability of MVC Crud / jqGrid and  I'm using the LINQ Repository.  How, and where would I hookup a user confirmation popup tied to the delete row button?   I can't figure out how and where to do this.  Out of-the-box, the delete row function works great, but it is imediate.  I need to offer the user a typical warning confirmation before submitting the record for actual delete.   Can someone tell me how to do that?  I'd like to see a code sample if possible.

2. The grid shows fine in all of my tests except I'm having trouble gettng the grid length to work.  Setting the default row count, or the active row count in the example or my code does not seem to work.  Is there a bug there?  I have seen this work in other jqGrid examples but I can't get it to work with MVC Crud.  Got any ideas?

3. Is there any future releases of this library planned.   I really like the simplicity of the approach.  As suggested, I'm using it for lookup table maintenance.  It's fast and easy for that purpose, and I"m simply overiding the default functions where needed for other more specific uses.   I'd love to know if there are any more releases planned.

Coordinator
Mar 29, 2010 at 1:22 PM

Glad to hear for finding it useful, to answer some of your questions...

I have been working out the country and not had much time to look at the project but new version should be out in a couple of weeks, got public holidays coming up so keen to finish the next version.  Main things being included are :

- Upgrade to MVC 2

- site patching and update ability (something i have been needing) either from the web or via zip upload

- Update to the latest JqGrid

- Some new  html helpers we use on our projects

- Ajax create, edit, delete (may be delayed till future release depending how dev goes).

 

As far as your other questions:

1) Delete confirmation will be in the next release, else for now override the deleteCell function in the grid class and make your own action link with a javascript confirm.

2) you can set the rows variable to set the no of rows shown by default, you can also set rowList variable with a comma separated string on rows to set the dropdown options for the rows.

What I do is make a project specific grid with all these options set then use that in my project not the mvccrud one eg

 

    public abstract class QuickstemGrid<T> : GenericDataGrid<T> where T : new()
    {
        protected QuickstemGrid(string gridName, string gridHeading, string jsonUrl, string editString, string deleteString, string primaryKey, string orderBy, DataGridRow[] datarows)
            : base(gridName, gridHeading, jsonUrl, editString, deleteString, primaryKey, orderBy, datarows )
        {
            extraGridSettings = @"height: 250, 
                                  width: 935";
            decimalFormat = "#,##0.00##";
            themeName = "south-street";
            rows = MvcApplication.cfg.grid_rows;
            edit_width = 25;
            delete_width = 50;
        }
    }

 

    public abstract class QuickstemGrid<T> : GenericDataGrid<T> where T : new()
    {
        protected QuickstemGrid(string gridName, string gridHeading, string jsonUrl, string editString, string deleteString, string primaryKey, string orderBy, DataGridRow[] datarows)
            : base(gridName, gridHeading, jsonUrl, editString, deleteString, primaryKey, orderBy, datarows )
        {
            extraGridSettings = @"height: 250, 
                                  width: 935";
            decimalFormat = "#,##0.00##";
            themeName = "south-street";
            rows = MvcApplication.cfg.grid_rows;
            edit_width = 25;
            delete_width = 50;
        }
    }

Let me know if you have any more recommendations

 

 

Mar 29, 2010 at 3:46 PM
Works fine to me also. I just implemented some behaviors using Jquery and CRUD overriding actionResults. This code puts the following behavior on the grid: Resize the grid to the desired height; Go to the the details page on doubleclick on rows; Puts a confirmation on the delete button then performs or not the delete action; Redirect to index with success or disallow message. function gridSetup() { if ($("div.ui-jqgrid-bdiv")) { $('.ui-jqgrid-bdiv').css("height", "440px"); $("tr").dblclick(function(event) { // sets link to details view on table rows var itemid = $(this).children().eq(1).find('a').attr('href').split('/'); itemid = itemid[itemid.length - 1]; window.location.href = window.location.href + "/details/" + itemid }); $("td[title='Delete']").click(function(event) { var answer = confirm('Are you sure you want to delete this item'); if (!answer){ return false; } }); } } public override ActionResult Delete(int id) { if (User.IsInRole(@"Admin")) { DeleteItem(id); TempData["harmonizationMessage"] = "
  • Item successfully deleted
"; return RedirectToAction("Index"); } else { TempData["HarmonizationMessage"] = "
  • You don't have sufficient access rights to delete
"; return RedirectToAction("Index"); } }
Apr 2, 2010 at 12:33 PM

This looks like it would work for me, but where are you wiring up the gridSetup() function?   Are you creating a new render method for that code in MVCCrud?  Or are you sticking it in the view somehow?

Thanks!

 

Apr 3, 2010 at 2:08 AM
It goes in the view.  In occurrence in the master page with a JS include.

Claude

On Fri, Apr 2, 2010 at 8:33 AM, bcox <notifications@codeplex.com> wrote:

From: bcox

This looks like it would work for me, but where are you wiring up the gridSetup() function?   Are you creating a new render method for that code in MVCCrud?  Or are you sticking it in the view somehow?

Thanks!

 

Read the full discussion online.

To add a post to this discussion, reply to this email (mvccrud@discussions.codeplex.com)

To start a new discussion for this project, email mvccrud@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Claude Bérubé, PMP
claude.berube@gmail.com
514-529-0338
Apr 4, 2010 at 12:55 PM

Claude:

Thanks for the help.  I'm still a bit lost.   I'm trying to figure out where and how the gridSetup() function would get called.   It does not appear that this is a standard call from jqGrid.  

Could you answer a couple more questions for me:

1. Does the jquery setupGrid function get called somehow automatically by jqGrid, or MVCCrud, or do I have to wire it up somehow?

2. Do I need somehow need to modify the href generated in the MVCCrud GenericDataGrid.cs deleteCell setup to include an onClick handler reference to setupGrid?

3. Do I need to make the setupGrid function into a $(document).ready(function() { so that it auto loads somehow?

Your approach is exactly what I'm trying to do.  I want to intercept the "Delete" link selection on the client and do a confirm popup, then if the user says "yes" then forward on to the controller as you show in your code example.  I just can't figure out how best to wireup the script to get it to work with MVCCrud.   I'm new to both jquery, and jqGrid.  It appears from the code you posted that jquery has the ability to trap the onclick event based on the TD tag without having to have an onclick handler attached to the href, is that true?

I've tried several approaches to get this to work.  I've created a separate .js and included it in the Master page.   I've added a renderGridSetup() method in theMVCCrud GenericDataGrid.cs.   I have not tried he methods mentioned above yet, but I'm not seeing where or how best to hookup the setupGrid method.  

Can you please send me another clue?

Thanks again for your help...

Apr 4, 2010 at 3:13 PM
As the grid provides a callback parameter, it is not necessary to wrap it into a jQuery document ready function. It is most probably more reliable than a document ready function as it is always triggered after grid load.

Use  the Grid load complete parameter.
loadComplete : gridsetUp,

I use this code myself on my app. So, it should be pretty reliable. I would suggest to keep  a global .js file.

function gridSetup() { 
if ($("div.ui-jqgrid-bdiv").length > 0)  // extra precaution, 
  { 
    $('.ui-jqgrid-bdiv').css("height", "440px");  // reset grid height
 
$("tr").dblclick(function(event) { // sets link to details view on table rows 
var itemid = $(this).children().eq(1).find('a').attr('href').split('/'); 
itemid = itemid[itemid.length - 1]; 
window.location.href = window.location.href + "/details/" + itemid 
}); 
 
// prompt on delete
  $("td[title='Delete']").click(function(event) {
var answer = confirm('Are you sure you want to delete this item'); 
if (!answer){ return false; } 
}); 
  }
}

Claude

On Sun, Apr 4, 2010 at 8:56 AM, bcox <notifications@codeplex.com> wrote:

From: bcox

Claude:

Thanks for the help.  I'm still a bit lost.   I'm trying to figure out where and how the gridSetup() function would get called.   It does not appear that this is a standard call from jqGrid.  

Could you answer a couple more questions for me:

1. Does the jquery setupGrid function get called somehow automatically by jqGrid, or MVCCrud, or do I have to wire it up somehow?

2. Do I need somehow need to modify the href generated in the MVCCrud GenericDataGrid.cs deleteCell setup to include an onClick handler reference to setupGrid?

3. Do I need to make the setupGrid function into a $(document).ready(function() { so that it auto loads somehow?

Your approach is exactly what I'm trying to do.  I want to intercept the "Delete" link selection on the client and do a confirm popup, then if the user says "yes" then forward on to the controller as you show in your code example.  I just can't figure out how best to wireup the script to get it to work with MVCCrud.   I'm new to both jquery, and jqGrid.  It appears from the code you posted that jquery has the ability to trap the onclick event based on the TD tag without having to have an onclick handler attached to the href, is that true?

I've tried several approaches to get this to work.  I've created a separate .js and included it in the Master page.   I've added a renderGridSetup() method in theMVCCrud GenericDataGrid.cs.   I have not tried he methods mentioned above yet, but I'm not seeing where or how best to hookup the setupGrid method.  

Can you please send me another clue?

Thanks again for your help...

Read the full discussion online.

To add a post to this discussion, reply to this email (mvccrud@discussions.codeplex.com)

To start a new discussion for this project, email mvccrud@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Claude Bérubé, PMP
claude.berube@gmail.com
514-529-0338
Apr 5, 2010 at 4:29 PM

I realize the Softwarehouse.MvcCrud.dll must be modified as it is not included in the original release.

Just add it to the generidDateGrid class in the method renderGrid.

jQuery('#{0}').jqGrid({{
                            url: '{1}',
                            ...
                            loadComplete: gridSetup,

                            ...

Apr 6, 2010 at 11:41 AM

Claude:

YEAH!  Works great!  

It took me a while to figure out that I had inserted '' around the gridSetup call in the loadComplete event parameter.   I had done everything right except I stuck quotes around the call.   Nothing happend at all.  Once I removed the quotes, everything worked great!

I'm still very new to jquery, and jqGrid.   Getting better now...

Thanks for your help!

 

Apr 13, 2010 at 3:07 AM

As I was revising the generidDateGrid, I realised the callback method name could be passed as parameter.  I harcoded it but, if you need different behavior you should probably pass it on instantiation.

Same for me, pretty new guy in C#. Looks great so far! 

Claude