s.sam
s.sam

Reputation: 133

How to send Parameter to an action, using formatter: 'showlink' in jqGrid 4.6.0 in MVC

I have a column named " CONTRACT_REQ_SUBJECT " in my jqGrid . and i want to make it a link that redirects to another action with sending parameter to that action. and I want to get this parameter from a different column of this jqgrid . and of course i want the text to be the value of CONTRACT_REQ_SUBJECT that i get from database.

here is my Code :

{  name:'CONTRACT_REQ_SUBJECT',index:'CONTRACT_REQ_SUBJECT',edittype:'select'  , formatter: 'showlink'  , formatoptions: { baseLinkUrl: '/Home/Steps_Details/' , idName: 'CONTRACT_REQ_SUBJECT' }   },  

Everything is ok , I just can't send the parameter to the action. Maybe it will work with " addParam: " , but i don't know how to use it.

Thanks in Advance...

UPDATE THE QUESTION :

@Oleg Thanks for your solutions in comments, but I couldn't solve this problem. so i decided to do it in another way like below codes:

 {  name:'CONTRACT_REQ_SUBJECT',index:'CONTRACT_REQ_SUBJECT',edittype:'select'  , formatter: 'showlink'  , formatoptions: { baseLinkUrl: '/Home/Steps_Details/' , idName: 'CONTRACT_REQ_SUBJECT'  , addParam : "Contract_Req_Id= 123" }   }, 

And now the problem is that instead of 123(in my above code) I want to send the value of " CONTRACT_REQ_ID " of the current row to my controller and don't know how to do this.

Is there a way to save the " CONTRACT_REQ_ID " into a variable and then sending the variable as parameter to my action ?

Maybe something like this :

var myGrid = $('#list'),
selRowId = myGrid.jqGrid ('getGridParam', 'selrow'),
celValue = myGrid.jqGrid ('getCell', selRowId, 'CONTRACT_REQ_ID');

But i don't know where to place it in my code. My code is :

 <script type="text/javascript">
$(document).ready(function () {
    $('#list').jqGrid({
        caption: "گزارش پیگیری قراردادها",
        url: '@Url.Action("Get_Contracts_Steps","Home")',
        datatype: 'json',
        jsonReader: {
            root: "Rows",
            page: "Page",
            total: "Total",
            records: "Records",
            repeatitems: true,
            userdata: "UserData",
            id: "Vahed_Descript",
            cell: "RowCells"
           // ,  data: { REQ_UNIQE: "REQ_UNIQE" },
        },
        mtype: 'GET',

        //columns names
        colNames: [' عنوان واحد ',
                            ' کد دبیرخانه ',
                            ' شماره درخواست ',
                            ' شرح درخواست ',
                            ' مبلغ برآوردی ',
                            ' تاریخ ثبت درخواست',
                            ' تاریخ تایید مدیر اجرایی ',
                            ' تاریخ تایید قائم مقام / معاونت ',
                            ' تاریخ ارسال درخواست به تدارکات ',
                            ' تاریخ اخذ استعلام ',
                            ' تاریخ ارسال پاکات قیمت',
                            ' تاریخ تایید بودجه- درخواست ',
                            ' تاریخ بازگشایی پاکات',
                            'تاریخ تایید صورت جلسه استعلام ',
                            ' تاریخ نامه احراز صلاحیت ',
                            ' تاریخ اخذ مدارک  ',
                            'تاریخ تهیه پیش نویس قرارداد ',
                            'تاریخ ارسال پیش نویس به دفتر  IT',
                            'تاریخ تایید پیش نویس توسط معاون',
                            'تاریخ تایید پیش نویس توسط مدیر',
                            ' تاریخ ثبت پیش نویس در سامانه کتاب ما ',
                            ' تاریخ تایید بودجه-پیش نویس ',
                            'تاریخ ارسال به ممیزی ',
                            'تاریخ تایید ممیزی',
                            'تاریخ تهیه نسخ قرارداد',
                            'تاریخ امضای شرکت',
                            'تاریخ امضاو ابلاغ قرارداد',
                            'شماره قرارداد ',
                            '',
                            ' نمایش جزییات ' 
        ],
        //columns model

        colModel: [
            { name: 'DESCRIPT', index: 'DESCRIPT', align: 'right'  },
            { name: 'DABIR_VAHED_CODE', index: 'DABIR_VAHED_CODE', align: 'right' },
            { name: 'CONTRACT_REQ_ID', index: 'CONTRACT_REQ_ID', align: 'right' },

            { name: 'CONTRACT_REQ_SUBJECT', index: 'CONTRACT_REQ_SUBJECT', edittype: 'select' 
                , formatter: 'showlink'
                , formatoptions: {
                    baseLinkUrl: '/Home/Steps_Details/', addParam: '&CONTRACT_REQ_ID=123' , idName: 'CONTRACT_REQ_SUBJECT'
                  } 
            },
            { name: 'AMNT_TOT_ESTIMATE', index: 'AMNT_TOT_ESTIMATE', align: 'center',  formatter: 'currency',
                formatoptions:
                {  decimalSeparator: '.', thousandsSeparator: ',', decimalPlaces: 0  }
            },
            { name: 'Req_Creation_Date', index: 'Req_Creation_Date', align: 'center'   },
            { name: 'Req_Exec_Confirm', index: 'Req_Exec_Confirm', align: 'center'  },
            { name: 'Req_Moavenat_Cnfrm', index: 'Req_Moavenat_Cnfrm', align: 'center'  },
            { name: 'SendToTadarokat', index: 'SendToTadarokat', align: 'center' },
            { name: 'GotEstelam', index: 'GotEstelam', align: 'center' },
            { name: 'SendPricePockets', index: 'SendPricePockets', align: 'center' },
            { name: 'Req_Budg_Cnfrm', index: 'Req_Budg_Cnfrm', align: 'center' },
            { name: 'OpenPockets', index: 'OpenPockets', align: 'center' },
            { name: 'ConfirmedEstelamSuratJalase', index: 'ConfirmedEstelamSuratJalase', align: 'center' },
            { name: 'EhrazSalahiatConfirmed', index: 'EhrazSalahiatConfirmed', align: 'center' },
            { name: 'GotDocs', index: 'GotDocs', align: 'center' },
            { name: 'Pre_Contract_Prepared', index: 'Pre_Contract_Prepared', align: 'center' },
            { name: 'sendprecontrtoIT', index: 'sendprecontrtoIT', align: 'center' },
            { name: 'PreContrConfirmed_Moaven', index: 'PreContrConfirmed_Moaven', align: 'center' },
            { name: 'PreContrConfirmed_Modir', index: 'PreContrConfirmed_Modir', align: 'center' },
            { name: 'SavePreCntrInKetabMa', index: 'SavePreCntrInKetabMa', align: 'center' },
            { name: 'Pre_BudgtCnfrm', index: 'Pre_BudgtCnfrm', align: 'center' },
            { name: 'SendToMomayeziDate', index: 'SendToMomayeziDate', align: 'center' },
            { name: 'Pre_MomayzCnfrm', index: 'Pre_MomayzCnfrm', align: 'center' },
            { name: 'ContrVersionsPreparedDate', index: 'ContrVersionsPreparedDate', align: 'center' },
            { name: 'CompanySignedVersionsDate', index: 'CompanySignedVersionsDate', align: 'center' },
            { name: 'ContrSignedDate', index: 'ContrSignedDate', align: 'center' },
            { name: 'CONTR_NO', index: 'CONTR_NO', align: 'center' },
            { name: 'REQ_UNIQE', index: 'REQ_UNIQE', width: 1, align: 'left', hidden: true },

            { name: 'Link', formatter: function (cellvalue, options, rowObject) {
                var x = '@Html.ActionLink("جزییات", "Steps_Details", "Home", new { REQ_UNIQE = "id" }, new { @style = "color:Blue;font-weight:bold;" })';
                return x.replace("id", rowObject[28]);
            }, align: 'center', width: 150,editurl: ' / Home / Steps_Details / '
            }, 

       ],

    pager: $('#pager'),
    rowNum: 300,
    rowList: [10, 20, 40, 60, 80, 100, 150, 200, 300, 400, 500, 600, 800, 1000, 1200],
    sortname: 'CONTRACT_REQ_SUBJECT',
    sortorder: 'asc',
    viewrecords: true,
    altRows: true,
    shrinkToFit: false ,
    width: 'auto',
    height: '300px',
    hidegrid: false,
    direction: "rtl",
    gridview: true,
    rownumbers: true,
    footerrow: true,
    userDataOnFooter: true,
    scrollerbar: true,
    loadComplete: function() {
        $("tr.jqgrow:odd").css("background", "#E0E0E0");
    },
    loadError: function(xhr, st, err) {
        jQuery("#rsperror").html("Type: " + st + "; Response: " + xhr.status + " " + xhr.statusText);
    }
    , loadonce: true

})

      .jqGrid('navGrid', "#pager",
         {
             edit: false, add: false, del: false, search: true,   refresh: true
         })


      .jqGrid('navButtonAdd', '#pager', {
          caption: "", buttonicon: "ui-icon-print", title: "خروجي پي دي اف",
          onClickButton: function () {

              $("#list").jqGrid('excelExport', { url: '@Url.Action("Get_Contracts_Steps", "Home")' });
          }
      })

    function toolbarSearching() {
        $("#list").jqGrid('filterToolbar', {
            autosearch: true,
            stringResult: false,
            searchOnEnter: true,
            defaultSearch: "cn",
        });
    };



    $("#list").jqGrid('filterToolbar', {
        autosearch: true,
        stringResult: false,
        searchOnEnter: true,
        defaultSearch: "cn",
    });

    var maxNameLength = 10;
    $("input[id=gs_name]").blur(function () {
        var $th = $(this).closest(".ui-search-toolbar>th"),
            colIndex = $th[0].cellIndex,
            $colHeader = $th.parent().siblings(".ui-jqgrid-labels").children("th").eq(colIndex),
            colHeaderText = $colHeader.children("div").text();
        if (this.value.length > maxNameLength) {
            alert(colHeaderText + ' is longer than ' + maxNameLength + ' characters.');
        }
    });
    $('#gs_invdate').datepicker({
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true
    }); 

})

Upvotes: 1

Views: 263

Answers (1)

s.sam
s.sam

Reputation: 133

Here is how I did :

    { name: 'CONTRACT_REQ_SUBJECT', index: 'CONTRACT_REQ_SUBJECT', edittype: 'select' 
           , formatter: 'showlink'  , formatoptions: {
                    baseLinkUrl: '/Home/Steps_Details/', addParam: '&REQ_UNIQE=' , 
                      idName: 'CONTRACT_REQ_SUBJECT'
                  }

Upvotes: 1

Related Questions