views:

2548

answers:

3

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%3A4618/Por/GetBoxesForPorId?id=16

The url I want it to build is: http://localhost%3A4618/Por/GetBoxesForPorId/16

+4  A: 

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' }
                  ],
Sergio
A: 

That's close, but it doesn't seem to be quite right. You'd think 'cellvalue' is just the value of the cell, but it's not. See this topic:

http://stackoverflow.com/questions/1775524/how-to-get-a-jqgrid-cell-value

I'm trying to figure out a simple way to do a custom formatter that uses the cell's content. You'd think that would be pretty common . . .

A: 

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()

    };
Sergio