How can I replace comma with new line?

How can I replace comma with new line?

Zeeker4730Zeeker4730 Posts: 2Questions: 1Answers: 0

One of my column have this data : Function ID=rp005,Function Name=TestEditValue

and it show in the column like this :

due to the result, instead of showing comma I want it to make a new line.

I think I could use a .render in columnDefs and traget to [4] (reference column)
https://datatables.net/reference/option/columns.render

or who have better idea please guide me.

And here my code when I generate columns:

columns: [
                      {
                            "className": 'details-control',
                            "orderable": false,
                            "data": null,
                            "defaultContent": ''
                        },
                        {data: 'actionDate'},
                        {data: 'menu'},
                        {data: 'type'},
                        {data: 'reference'},
                        {data: 'actionBy'},
                        {data: 'field'},
                        {data: 'groupName'}
                    ],
                    "columnDefs": [
                        {"targets": [6], "visible": false}
                    ],

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Yep, columns.render is the way to go there.

  • Zeeker4730Zeeker4730 Posts: 2Questions: 1Answers: 0

    Ok, so I use this code Insert to columnDefs and It's work!!!

    {"targets": [4], "render": function (data, type, row) {
                                    return data.split(",").join("<br/>");
                                }
                            }
    
  • LenfantLenfant Posts: 12Questions: 2Answers: 0

    Hi all, I'm having the same problem as above, however I'm still unable to get this to work. can someone please advise?

    My code is below:

    dataTableClient = $('#ClientList').DataTable({

            "aaData": data.d.results,
            "aoColumns": [
                {
                  className: 'details-control',
                  orderable: false,
                  data: null,
                  defaultContent: '' 
                },
                { "mData": "AR_ClientName" },
                { "mData": "AR_IntroducerId" },
                { "mData": "AR_PracticeAreas.results", "defaultContent": "" },
                {
                 "mData": "ID",
                 "render": function(mData, type, row, meta) {
                    var returnText = "";
                    var url = _spPageContextInfo.webAbsoluteUrl + "/SitePages/NewClient.aspx?ItemID=" + mData;
                    returnText = "<a target='_blank' href=" + url + ">Click To Edit</a>";
                    return returnText;
                    }
                }
            ],
            "columnDefs": [
                {"targets": [3], "render": function (mData, type, row) {
                    return mData.split(",").join("<br/>");
                    }
                }
            ],
            order: [[1, 'asc']]
        });
    
  • LenfantLenfant Posts: 12Questions: 2Answers: 0

    Sorry forgot to add the error message, see below:

    mData.split is not a function

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    What is the data in the column? The split() method is used with a string. Sounds like it might be something other than a string.

    If you still need help please provide a link to your page or a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • LenfantLenfant Posts: 12Questions: 2Answers: 0

    Hi, yes I found that the mData was an object and not a string. I set a new variable as a string and used that to perform the split. This seemed to work.

    mData2 = mData + ''

    Many thanks.

Sign In or Register to comment.