Search code examples
jqgrid

JQGRID formatter only apply once


I'm using a formatter on one of my Jqgrid column to create some line breaks each time the delimiter " ; " is found in the cell but I don't know why it only works on the first one. If a cell contain more than one delimiter then it not creates a second line break and the text stays in line after the first line break.

$("#jqGrid").jqGrid({
            datatype: 'local',
            data: MaingridQueryResults_1,
            colModel: [
                {name: 'id_contact', label: 'id',  align:'left', hidden: true, width:30,}, 
                {name: 'company_name', label: 'Société', align:'left', width:0, formatter:currencyFmatter}, 
                {name: 'last_name', label: 'Nom', align:'left', width:0},
                {name: 'first_name', label: 'Prénom', align:'left', width:0},


            ],


function currencyFmatter (cellvalue) {

            return cellvalue.replace(/\s;\s/,'<br/>');

        }

What am I missing ?


Solution

  • replace - replace only the first occurance use replaceAll instead like this

    function currencyFmatter (cellvalue) {
        return cellvalue.replaceAll(';','<br/>');
    }