Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
How to edit and save multiple rows in jqgrid
15/07/2009
07:17
Avatar
hariom964
Member
Members
Forum Posts: 3
Member Since:
14/07/2009
sp_UserOfflineSmall Offline

Hi,

I want to edit multiple rows in jqgrid and save them into database by using Asp.net mvc 1.0. Please provide me suitable example for this.

Regards,

Hari

16/07/2009
01:25
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

What do you use inline edit, cell edit or form edit?

If you use cell editing you can use clientArray in the url and then getChangedCells method.

Regasrds

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

16/07/2009
01:50
Avatar
hariom964
Member
Members
Forum Posts: 3
Member Since:
14/07/2009
sp_UserOfflineSmall Offline

tony said:

Hello,

What do you use inline edit, cell edit or form edit?

If you use cell editing you can use clientArray in the url and then getChangedCells method.

Regasrds

Tony


Thanks Tony,

I am using cell edit. I am very new to jquery and jqgrid. Can you please give a suitable example with some code to implement it in asp.net mvc or any other better. Following is my view code(Index.aspx)

        jQuery(document).ready(function() {

            jQuery("#list").jqGrid({

                url: '/Home/GetGridData/',

                datatype: 'json',

                mtype: 'POST',

                colNames: ['Customer ID', 'Contact Name', 'Address', 'City', 'Postal Code'],

                colModel: [

                  { name: 'CustomerID', index: 'CustomerID', width: 100, align: 'left', editable: true },

                  { name: 'ContactName', index: 'ContactName', width: 150, align: 'left', editable: true },

                  { name: 'Address', index: 'Address', width: 300, align: 'left', editable: true },

                  { name: 'City', index: 'City', width: 150, align: 'left', editable: true },

                  { name: 'PostalCode', index: 'PostalCode', width: 100, align: 'left', editable: true }

                ],

                rowNum: 10,

                rowList: [10, 20, 30],

                imgpath: '/scripts/themes/sand/images',

                pager: jQuery('#pager'),

                sortname: 'CustomerID',

                viewrecords: true,

                sortorder: "desc",

                caption: "Cell Edit Example",

                forceFit: true,

                cellEdit: true,

                cellsubmit: 'clientArray',

                editurl: "/Home/GridSave",

                afterEditCell: function(id, name, val, iRow, iCol) {

                    if (name == 'invdate') {

                        jQuery("#" + iRow + "_invdate", "#celltbl").datepicker({ dateFormat: "yy-mm-dd" });

                    }

                },

                ondblclickrow: function(id) { 

                  if (id) { 

                   var grid = jquery('#grid'); 

                    if(id !== lastsel) {

                      jquery('#list').restorerow(lastsel) 

                        jquery('#list').editrow(id, true); 

                     lastsel = id; 

                    } 

                   else { 

                      jquery('#list').saverow(lastsel); 

                      lastsel = -1; 

                    } 

                 }

                }, 

                afterSaveCell: function(rowid, name, val, iRow, iCol) {                   

                    if (name == 'amount') {

                        var taxval = jQuery("#celltbl").getCell(rowid, iCol + 1);

                        jQuery("#celltbl").setRowData(rowid, { total: parseFloat(val) + parseFloat(taxval) });

                    }

                    if (name == 'tax') {

                        var amtval = jQuery("#celltbl").getCell(rowid, iCol - 1);

                        jQuery("#celltbl").setRowData(rowid, { total: parseFloat(val) + parseFloat(amtval) });

                    }

                }

            })           

            .navGrid(pager, { edit: true, add: false, del: true, search: true }, {}, {}, { url: "/Home/Delete" });

        });

Following is my Controller code.

namespace MvcApplication1.Controllers {

    [HandleError]

    public class HomeController : Controller {

        public ActionResult Index() {

            ViewData["Message"] = “Welcome to ASP.NET MVC!”;

            return View();

        }

        public ActionResult About() {

            return View();

        }

        [AcceptVerbs(HttpVerbs.Post)]

        public ActionResult GetGridData(string sidx, string sord, int page, int rows) {

            return Content(JsonHelper.JsonForJqgrid(GetDataTable(sidx,sord,page,rows), rows, GetTotalCount(), page), “application/json”);

        }

        public DataTable GetDataTable(string sidx, string sord, int page, int pageSize) {

            int startIndex = (page-1) * pageSize;

            int endIndex = page * pageSize;

            string sql = @”WITH PAGED_CUSTOMERS  AS

                        (

                       SELECT CustomerID, ContactName, Address, City, PostalCode,

                       ROW_NUMBER() OVER (ORDER BY ” + sidx + @” ” + sord + @”) AS RowNumber

                       FROM CUSTOMERS

                        )

                        SELECT CustomerID, ContactName, Address, City, PostalCode

                        FROM PAGED_CUSTOMERS

                        WHERE RowNumber BETWEEN ” + startIndex + @” AND ” + endIndex + @”;”;

            DataTable dt = new DataTable();

            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["mainConnection"].ConnectionString);

            SqlDataAdapter adap = new SqlDataAdapter(sql,conn);

            var rows=adap.Fill(dt);

            return dt;

        }

        public int GetTotalCount() {

            string sql = @”SELECT COUNT(*) FROM Customers”;

            SqlConnection conn=null;

            try {

                 conn= new SqlConnection(ConfigurationManager.ConnectionStrings["mainConnection"].ConnectionString);

                SqlCommand comm = new SqlCommand(sql, conn);

                conn.Open();

                return (int)comm.ExecuteScalar();

            } catch {

            } finally {

                try {

                    if (ConnectionState.Closed != conn.State) {

                        conn.Close();

                    }

                }catch {

                }

            }

            return -1;

        }

    }

}

Regards 

Hari

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
51 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information