Search code examples
javascriptjavaspringspring-mvcjqgrid

How do I assign object parameters from the formatter function of jQgrid to a function?


I'm working on the Spring-Mvc project.

I'm currently using JQgrid to draw a list. My problem is that I can't use variables as a function

This is where I'm having trouble.

        {name : 'product_id',               
            index : 'pid',          
            align : 'center',           
            sortable : false,
            formatter : function(cellValue, options, rowObject) {
                return '<a href="#" onclick="onCellSelect(\''+ cellValue +'\','+ rowObject +');" >'+ cellValue +' </a>';
            } 
            },

The rowObject is not available because it is JSONdata.

this is error

Uncaught SyntaxError: Unexpected identifier

onCellSelect([object Object]) // rowobject 

How can you solve this problem?


Solution

  • I've solved this problem now, but it's not a fundamental solution. It's just a means of getting data. If there is no solution to this problem, I will present it as a solution.

    My solution is to bring in one unique value and get it through a repetitive function.

     return '<a href="#" onclick="onCellSelect(\''+ cellValue +'\','+ rowObject.seq_no +');" >'+ cellValue +' </a>';
    ...
    
    function onCellSelect(cellValue, seq_no) {
    
        var selarrrow = jQuery("#chargeGoodsList").jqGrid("getDataIDs");
        $(selarrrow).each(function(i){  
            if (seq_no == $('#chargeGoodsList').getCell(selarrrow[i], 'seq_no')) {
                title = $('#chargeGoodsList').getCell(selarrrow[i], "title")
                explanation = $('#chargeGoodsList').getCell(selarrrow[i], "explanation")
        ...
    

    I believe there is a better solution than this. If there is a good solution, please answer.