Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:46:01+00:00 2026-05-30T09:46:01+00:00

I am using MVC 4 + EF 4.1 with jqgrid. I am new with

  • 0

I am using MVC 4 + EF 4.1 with jqgrid.
I am new with HTML & Javascript and I am trying without success opening a custom edit jquery dialog inside jqgrid. If you have better methods to implement my desired behaviour, they would be welcome.

I have the following jquery dialog script, attached to the class=’openDialog‘, which already works fine for other purposes:

  $.ajaxSetup({ cache: false });

$(document).ready(function () {
    $(".openDialog").live("click", function (e) {
        e.preventDefault();

        $("<div></div>")
            .addClass("dialog")
            .attr("id", $(this).attr("data-dialog-id"))
            .appendTo("body")
            .dialog({
                height: $(this).attr("data-dialog-alt"),
                width: $(this).attr("data-dialog-larg"),
                autoResize: $(this).attr("data-dialog-autosize"),
                position: 'top',
                title: $(this).attr("data-dialog-title"),
                close: function () { $(this).remove() },
                modal: true,
                buttons: { "Ok": function () { $(this).dialog("close"); } }
            })
            .load(this.href);
    });

    $(".close").live("click", function (e) {
        e.preventDefault();
        $(this).closest(".dialog").dialog("close");
    });
});

This is what I’m trying to do. This is just a test with double click event, if it works I will put the code inside a specific button.

jqgrid

    ..........
    { name: 'act', index: 'act', width: 75, sortable: false, search: false }
        ],
        ondblClickRow: function (id) {
            if (id != null) {
               // here I would like to launch the open dialog with a similar code: 
               // "<a class='openDialog' data-dialog-id='myEditDlg' data-dialog-autosize='false' data-dialog-alt='580' data-dialog-larg='740' data-dialog-title='test dialog' href='/mycontroller/EditDlg/myid'>test</a>"
            }
        },
        pager: '#jqpager',
       ....

MORE DETAILS

Basically, now I am using a custom formatter, where I put a button styled anchor for each button/action I need; for example:

         .....
         gridComplete: function () {
            applyZebra("mygrid");
            var ids = grid.jqGrid('getDataIDs');
            var rows = grid.jqGrid('getRowData');
            for (var i = 0; i < ids.length; i++) {

                var row = rows[i];
                var t = row['myrow'];
                var cl = ids[i];

                tst = '<a class="mybuttonclass openDialog" data-dialog-id="tckDetDlg" data-dialog-autosize="false" data-dialog-alt="580" data-dialog-larg="740" data-dialog-title="test dialog" href="/mycontrolller/testDlg/' + t + '"></a>';

                $("#jqTicketgrid").jqGrid('setRowData', ids[i], { act: tst });
            }
        },
        .....

Where mybuttonclass styles the anchors like a button…

Thank you very much for your help!
Best Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:46:02+00:00Added an answer on May 30, 2026 at 9:46 am

    I am not sure that I understand correct your requirements. I would recommend you to use jQuery.jqGrid.dynamicLink.js which I described in the answer and which you can download from here or the last version from here (and download here). The usage of formatter: 'dynamicLink' is very easy and you can implement practically every link inside of jqGrid. You can use onClick callback which would create the dialog which you need.

    One more remark to your code. On every click you create <div> which represent the dialog and place it in the <body> of the page. The close event only hide the div, but not remove it from the body. So the first problem: your page will be longer and longer on every click. The second problem is the possibility to get id duplicates which are not permitted in HTML and if you do add different elements with the same id you can have many very strange effects. So you should be very careful in the usage of data-dialog-id attribute from your current code.

    UPDATED: I wanted to comment the code from gridComplete which you posted. It’s not effective and you can use custom formatter to get more clear and effective code. You don’t posted the full code of jqGrid which you use, but I suppose that you have at least two columns in the colModel: ‘act’ and ‘myrow’. You cant to place in ‘act’ column the <a> elements having href which are constructed based on the value from the ‘myrow’ column.

    What the current code do. 1) the grid will be build and placed on the page with empty ‘act’ column. Then inside of gridComplete you do the following: a) call getDataIDs which goes through the full grid and collect the ids from every row in the array ids. b) call getRowData which goes through the full grid and collect all data from all column in objects and place the objects in array rows. c) get the content of the ‘myrow’ column, construct <a> and place it in 'act' column *in every row of grid. You should additionally understand that changing of one element on the page follows the web browser have to recalculate the position of every element on the page.

    So to improve the performance of the page you should first of all reduce the modifications of the elements on the page. The most effective way to rewrite the code and have the same results is to use custom formatter. In you case you can just include in 'act' from colModel an additional property:

    { name: 'act', index: 'act', width: 75, sortable: false, search: false,
        formatter: function (cellvalue, options, rowObject) {
            return '<a class="mybuttonclass openDialog" data-dialog-id="tckDetDlg" data-dialog-autosize="false" data-dialog-alt="580" data-dialog-larg="740" data-dialog-title="test dialog" href="/mycontrolller/testDlg/' +
                rowObject.myrow + '"></a>';
        }}
    

    You should additionally verify that you use gridview: true option of jqGrid. The modified code will do the following. During constructing the HTML fragment of the body of the grid the full HTML fragment will be build as one string and will be placed to the HTML page in one operation. In the moment the web browser will recalculate position of other elements on the page and all will be done. So the code will be the same, it will be shorter, easy to read and it will work much more effective especially in case of many rows of the grid.

    If you would use dynamicLink formatter which I suggested you before the code can be like the following:

    { name: 'act', index: 'act', width: 75, sortable: false, search: false,
        formatter: 'dynamicLink', formatoptions: {
            onClick: function (rowid, iRow, iCol, cellValue, e) {
                var myrow = $(this).jqGrid('getCell', rowid, 'myrow');
                $("<div>", {id: "tckDetDlg"})
                    .addClass("dialog")
                    .appendTo("body")
                    .dialog({
                        height: 580,
                        width: 740,
                        autoResize: false,
                        position: 'top',
                        title: 'test dialog',
                        close: function () { $(this).remove() },
                        modal: true,
                        buttons: { "Ok": function () { $(this).dialog("close"); } }
                    })
                    .load('/mycontrolller/testDlg/' + myrow);
            }
        }}
    

    The above code will be clear to read and understand in my opinion. The code from onClick will be the same as with you could use inside of ondblClickRow. In both cases you need just know the rowid only. So you can place the code of onClick in a function instead of the usage of anonymous function and call the function in both cases:

    // first define the callback function which we will use later
    var myClickHandle = function (rowid) {
            var myrow = $(this).jqGrid('getCell', rowid, 'myrow');
            $("<div>", {id: "tckDetDlg"})
                .addClass("dialog")
                .appendTo("body")
                .dialog({
                    height: 580,
                    width: 740,
                    autoResize: false,
                    position: 'top',
                    title: 'test dialog',
                    close: function () { $(this).remove() },
                    modal: true,
                    buttons: { "Ok": function () { $(this).dialog("close"); } }
                })
                .load('/mycontrolller/testDlg/' + myrow);
        };
    
    ...
    // define the grid
    $("#jqTicketgrid").jqGrid({
        ...
        colModel: [
            ...
            { name: 'act', index: 'act', width: 75, sortable: false, search: false,
                formatter: 'dynamicLink', formatoptions: { onClick: myClickHandle } }
            ...
        ],
        ondblClickRow: function (rowid) {
            myClickHandle.call(this, rowid);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with JQGrid using ASP.NET MVC. I'm trying to follow this
I'm using jqGrid with mvc 2 like this: jQuery(#extension_grid).jqGrid({ url: '/Extension/Report', datatype: json, direction:
I am using the JQGrid plugin on an MVC project. I am trying to
I've implemented a functioning jqgrid in MVC using a style similiar to: <script type=text/javascript>
i m using jqgrid with mvc 3, I want to add Edit and Delete
I'm using MVC to validate some html text boxes on a page, for example
I'm using MVC 2, and the Html.EditorForModel() to allow me to display an editor
I have this sample MVC project using jQuery grid. There is only one problem
I'm using jqGrid in an ASP.NET MVC webapp. When the page first loads, the
I'm currently using jqGrid and ASP.Net MVC. With my current project, my goal is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.