Jqgrid put phone mask on column output in Jqgrid?

Asked

Viewed 74 times

0

Code of the table that mounts JQGRID:

var grid = $("#jqGrid").jqGrid({
    url:'/Portaria/Agenda/Listar',
    mtype: 'GET',
    datatype: 'json',
    colModel: [
        { label: 'Id', name: 'id', width: 50 },
        { label: 'Nome', name: 'nome', width: 250 },         
        { label: 'Telefone1', name: 'telefone1', width: 80 },         
        { label: 'Telefone2', name: 'telefone2', width: 80 },         
        { label: 'Telefone3', name: 'telefone3', width: 80 },         

    ],

    loadonce: true,
    pager: '#jqGridPager',
    rowNum: 10,
    rowList: [10, 20, 30, 50],
    viewrecords: true,
    height: 250

});
$("#jqGrid").jqGrid('navGrid', 'jqGridPager', { edit: false, add: false, del: false })

the Return

inserir a descrição da imagem aqui

How to format the fields Phone1, Phone2, Phone3, putting the mask?

exemplo: (99)9999-9999?9

1 answer

0


 var grid = $("#jqGrid").jqGrid({
        url: url,
        datatype: 'json',
        mtype: 'GET',  

        postData: {
                  nome: function () { return jQuery("#nome").val(); }
        }, 
        colModel: [
            { label: 'Id', name: 'id', width: 50 },
            { label: 'Nome', name: 'nome', width: 250 },         
            { label: 'Telefone1', name: 'telefone1', width: 180, formatter: colocaMascara },         
            { label: 'Telefone2', name: 'telefone2', width: 180, formatter: colocaMascara },         
            { label: 'Telefone3', name: 'telefone3', width: 180, formatter: colocaMascara }         
        ],

        viewrecords: true,
            rowNum: 20,
            rowList: [20, 40, 100],
            height: "auto",
            //height: 400,
            emptyrecords: "Nenhum Cliente",
            loadtext: "Buscando e carregando...",
            //rowNum: 20,
            pager: "#jqGridPager",
            loadonce: true

    });

Calls the function:

function colocaMascara(cellvalue, options, rowObject) {
    var length = cellvalue.length;
    var telefoneFormatado;


if (length === 0) {
    telefoneFormatado = "";
}
if (length === 10) {
    telefoneFormatado = '(' + cellvalue.substring(0, 2) + ') ' + cellvalue.substring(2, 6) + '-' + cellvalue.substring(6, 10);
} else if (length === 11) {
    telefoneFormatado = '(' + cellvalue.substring(0, 2) + ') ' + cellvalue.substring(2, 6) + '-' + cellvalue.substring(6, 11);
}
return telefoneFormatado;

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.