0

i need to change some cells from one of the columns in my jqgrid. I need to put a conditional statements to differentiate each cell, but I have 4.0.0 jqGrid version and the colModel hasn't got the attribute cellattr

Now, this is what I have:

colModel:[
            {
                name     : 'compras',
                index    : 'num_compras',
                jsonmap  : 'num_veces',
                width    : 50,
                edittype :'select',
                formatter:'showlink',
                formatoptions:
                {
                    baseLinkUrl:'/myURL'
                }
            }
]

I need to make not clickable some of that cells, because they are like anchor tag.

Thank you in advance!!

Villapalos
  • 677
  • 9
  • 15

2 Answers2

1

You can try to use formatter: "dynamicLink" instead of formatter:'showlink'. I suggested if in the old answer. It should work with retro version 4.0.0. You can download it here. It is very flexible and I think you would be able implement all your requirement. Nevertheless I'd recommend you to upgrade to the current version of free jqGrid (version 4.13.0) because the version 4.0.0 is dead since a long time. You can try free jqGrid just by replacing the URLs to jqGrid files to the URLs described in the wiki.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • the problem is that I can't download neither ´formatter: "dynamicLink"´ nor version 4.13.0, because I'm using an entrerprise software and is not possible to modify the structure. But thank you very much! – Villapalos Mar 03 '16 at 08:35
  • @Villapalos: You are welcome! Sorry, but I don't sure that I understand the problem with downloading. If you have access to [the page](https://github.com/OlegKi/jqGrid-plugins/blob/master/jQuery.jqGrid.dynamicLink.js), you can just use copy and pasted of the code. The code like `$.extend($.fn.fmatter, { newFormatter: function (cellValue, options, rowData) {...}});` and `$.extend($.fn.fmatter.newFormatter, {unformat: function (cellValue, options, elem) {...}});` **registers new formatter**, which you can use like *predefined formatters*: `formatter: "newFormatter"`. – Oleg Mar 03 '16 at 08:47
  • ok! I understood that I needed to download a file, my fault. Your solution is clearly better, but my jqGrid isn't very big and for me is simpler to do it as in my answer. Thanks – Villapalos Mar 03 '16 at 11:44
  • I mark yours as solution because is the best option, I have tried it. – Villapalos Mar 03 '16 at 14:52
  • @Villapalos: OK. I would recommend you additionally to consider to migrate now or later to the latest free jqGrid. The version 4.0.0 is dead and it calculate for example the width of columns in a wrong way for web browsers published in the last years (see [the answer](http://stackoverflow.com/a/10621951/315935) about the poblem in Chrome 19). I updated today my Chrome to version 49. What you would do for example if jqGrid 4.0.0 would not work at all (critical error) in the next version of Chrome? You will have to debug and fix jqGrid 4.0.0 yourself because nobody use it more... It's your risk. – Oleg Mar 03 '16 at 15:07
0

Finally, I've found the simplest solution in gridComplete function, as the following:

gridComplete: function(){
    var grid = jQuery(this);
    var ids = grid.jqGrid('getDataIDs');

    for(var i=0;i < ids.length;i++){
        if(grid.getCell(ids[i], 'my_column_identification') == 0){ //or other condition
                    grid.setCell(ids[i], 'my_column_identification', "", {'pointer-events': 'none', 'cursor': 'default'})
        }
    }
}
Villapalos
  • 677
  • 9
  • 15
  • The difference in the usage of `setCell` in the loop from the usage of `formatter` is the performance. I suppose that you use `gridview: true` option (which is changed to default in the last versions of jqGrid). If you use formatter then **the whole body of the grid (all rows and columns)** will be created as string first and then placed on the DOM of page. If you use `getCell` to modify **one cell** then **all existing elements** have to be at least verified or it's style or position could be changed. It has exponential complexity and much more slowly. I never recommend you to use the aproach – Oleg Mar 03 '16 at 08:52