1

I'm trying to hide a Row if a cell in it has the false value, so far I've tried using a formatter like this:

$("#list").jqGrid({
            //datatype: 'clientSide',
            colNames: ["Id", "Descrizione", "Data Vendita", "Disabilitato", "PISTA", 
                       "Piano Tariffario", "Data Validità Piano Tariffario", 
                       "PROMO", "Data Validità Promo", "CANONE CLIENTE NETTO MESE", 
                       "Vendibile", "Migrato"],
            colModel: [
                { name: "id"},
                { name: "descrizione", editable: true},
                { name: "dataInizVendita", editable: true, formatter:vendita},                          
                { name: "disabilitato", editable: true},
                { name: "pista", editable: true},
                { name: "pianoTariffario", editable: true},
                { name: "dataInizPiano", editable: true, formatter:piano},              
                { name: "promo", editable: true},
                { name: "dataInizPromo", editable: true, formatter:promo},
                { name: "canoneNetto", editable: true},
                { name: "disponibilita", editable: true, formatter:mostra},
                { name: "migrato", editable: true, width:150, sortable: false, resizable:false, formatter:bottone}          
            ],
            formatter: 'date', 
            formatoptions: { srcformat: 'd/m/Y', newformat: 'd/m/Y'},
            sortname: "id",
            sortorder: "asc"

        })

The formatter that I care about is mostra, if disponibilita is false, it must hide the row!

function mostra (cellvalue, options, rowObject)
{               

    if(rowObject.disponibilita == false)
    {               
        $("#"+rowObject.id).hide();
    }
    $("#list").trigger("reloadGrid");
    return rowObject.disponibilita;
}

I've tried using delRowdata too, but it doesn't remove it, and it can see when it's false and when it's not, because the if function works perfectly

Malignus
  • 115
  • 1
  • 13
  • 1
    Do you plan to delete the question next time like [your previous question](http://stackoverflow.com/questions/35295729/jqgrid-open-another-page-on-clicking-a-custom-edit-button/35295971#35295971)? The current question don't describe which version of jqGrid and from which fork ([free jqGrid](https://github.com/free-jqgrid/jqGrid), [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7) you use. One can just delete the item of data *before* it will be used by jqGrid, but the solution depends on the `datatype` which you use. The usage of `rowattr` is alternative – Oleg Feb 09 '16 at 17:22
  • 1) I deleted the question because I saw no answers and my question was wrong in the first place 2) I used the rowattr as you suggested, in the class I try to hide the row using .ui-widget-content .rowClass { display:"none"; } but it doesn't hide it, does it have a specific command to hide it? – Malignus Feb 10 '16 at 10:36
  • nevermind, it should be display: none;...... – Malignus Feb 10 '16 at 11:35
  • Sorry, but I still don't know which `datatype` you use and which version of jqGrid you use. The preferred way will be deleting the item from the data instead of hiding it, but one have to know the requested information. If you do use `rowattr` then you should post the code, which you tried and which is not worked. Because I have no other information I show how you can use `rowattr` correctly in my answer. – Oleg Feb 10 '16 at 19:56

2 Answers2

0

An alternative way is to use an each function to scan the tr and td data and hide when false

$('.hidefalse').click(function() {

$("#grid tr").each(function () {
var thisrow = $(this);

    $('td', this).each(function () {
        var value = $(this).text();

        if (value == 'false') {
            $(thisrow).fadeOut();
        }
     })

})

})

Demo

To automate it take out the click function

Demo

Tasos
  • 5,321
  • 1
  • 15
  • 26
0

It would be better to delete the data, which have false value in disponibilita column before the data will be processed by jqGrid. In case of datatype: "local" one should just modify the input data and then use data parameter with modifies input. In case of loading the data from the server one can use beforeProcessing callback to modify the data returned from the server.

Only if you can't implement the above scenarios because of some additional reasons, you can use rowattr callback in the following form

rowattr: function (item) { // !rowObject.disponibilita in your case
    if (item.closed) {
        return {style: "display:none;"};
    }
}

see the demo or in "class" form:

rowattr: function (item) {
    if (item.closed) {
        return {"class": "my-hide"};
    }
}

see another demo. You can see then both of the solutions works, but the page size is not correct.

Oleg
  • 220,925
  • 34
  • 403
  • 798