Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting JQGrid formatter: ‘showlink’ to work in MVC

My columns are showing up, it is generating an anchor for my link. The only problem is the url is badly formed for MVC

Here is the colModel:

                colModel: [

                  { name: 'RegName',  index: 'RegName', label: 'Region Name',width:90, align: 'center' },
                  { name: 'AccessNbr', index: 'AccessNbr', label: 'Access Number',width:80, align: 'center', formatter: 'showlink', formatoptions: {baseLinkUrl: '', showAction: 'GetBoxesForPorId', addParam: ''}  },
                  { name: 'TransmitedDt', index: 'TransmitedDt', label: 'TransmitedDt',  align: 'center' },
                  { name: 'BoxCount', index: 'BoxCount', label: 'Box Count', align: 'center' },
                  { name: 'PorId',  hidden:false ,index: 'PorId', label: 'Por ID', key:true ,formatter:'link', formatoptions: {target:'_new'}  }                           
                ]

Here is the url that it builds: http://localhost:4618/Por/GetBoxesForPorId?id=16

The url I want it to build is: http://localhost:4618/Por/GetBoxesForPorId/16

like image 302
Eric Brown - Cal Avatar asked Sep 11 '09 22:09

Eric Brown - Cal


2 Answers

Here's your answer :

 function formateadorLink(cellvalue, options, rowObject) {

            return "<a href=/Idiomas/Edit/"+ cellvalue + ">" + cellvalue + "</a>";
        }

in the grid definition:

   colModel: [
                        { name: 'id_idioma', index: 'id_idioma', width: 100, align: 'left',
                            formatter: formateadorLink
                        },
                        { name: 'nombre', index: 'nombre', width: 100, align: 'left' }
                  ],
like image 82
Sergio Avatar answered Sep 19 '22 08:09

Sergio


This is the way I did it:

  function LinkFormatter(cellvalue, options, rowObject) {

            return '<a href= <%= Url.Content("~/") %>' + cellvalue + ">Edit</a>";
        } 

Col Model

  colModel: [
                    { name: 'Id', index: 'Id', width: 50, align: 'left', hidden: true },
                    { name: 'Edit', index: 'Edit', width: 50, align: 'left', formatter: LinkFormatter },
                    { name: 'AgentName', index: 'AgentName', width: 250, align: 'left' },
                    { name: 'AgentType', index: 'AgentType', width: 250, align: 'left' },
                ],

In the server side

    var jsonData = new
    {
        total = 1,
        page = 1,
        records = agents.Count(),
        rows = (
                from row in agents
                select new
                {
                    i = row.Id,
                    cell = new[] {


                        row.Id.ToString(),
                        "Controller/Action/" + row.Id.ToString(),
                        row.Name,
                        row.Type
                    }
                }).ToArray()

    };
like image 20
Sanchitos Avatar answered Sep 21 '22 08:09

Sanchitos