' How should I remove the pattern from my data?

' How should I remove the pattern from my data?

hktnaydnhktnaydn Posts: 4Questions: 2Answers: 0

Guys, I've been dealing with this problem for an hour.
I'm pulling data from Google trends, there is a word I don't want in the data (') and I need to destroy them, I wrote a code like this, but I can't get the result I want

            {'data':'articles.0.articleTitle,
              render: function ( data) { 
                  **let articleTitle=data.replace(/&#39/g,"");**
                  return articleTitle;
            }

' How should I remove the pattern from my data?

This question has an accepted answers - jump to answer

Answers

  • hktnaydnhktnaydn Posts: 4Questions: 2Answers: 0

    ->>>>& # 3 9 ; I SHOULD REMOVE THIS

  • kthorngrenkthorngren Posts: 19,946Questions: 26Answers: 4,701
    Answer ✓

    I think it will depend on the source of your data. If you have Javascript or Ajax data then the above should work, note you will want ' with the ; at the end. However if you have HTML data you will probably need to use .replace(/'/g, "") with the apostrophe. The browser will render the apostrophe and that is what Datatables sees. You can use a console.log statement to see the actual data the Datatables has. Like this:
    http://live.datatables.net/lolamafi/1/edit

    Kevin

  • hktnaydnhktnaydn Posts: 4Questions: 2Answers: 0

    function unEscape(htmlStr) {
    htmlStr = htmlStr.replace(/</g , "<");
    htmlStr = htmlStr.replace(/>/g , ">");
    htmlStr = htmlStr.replace(/"/g , "\"");
    htmlStr = htmlStr.replace(/'/g , "\'");
    htmlStr = htmlStr.replace(/&/g , "&");
    return htmlStr;
    }

    {'data':'articles.0.articleTitle',
    render: function ( data, type, row ) {
    return unEscape(data);
    }
    },
    this saved me

Sign In or Register to comment.