La Croix
La Croix

Reputation: 111

How to strip tags in Jquery DataTables

I am using CodeIgniter and DataTables(link) with library IgnitedDatatables(link).

I dont know how to use something like strip_tags() in DataTables. I just need to remove all html tag output from JSON data.

My JavaScript Code :

var table = $('#dtslider').DataTable({
  ajax: {
    url: baseurl + 'admin/Administrator/getdata_slider',
    type: "POST"
  },
  processing: true,
  serverSide: true,
  columns: [{
    data: "idHome",
    visible: false
  }, {
    data: "jdlHome"
  }, {
    data: "isiHome",
    sType: 'html'
  }, {
    data: "Actions",
    searchable: false
  }],
  "order": [
    [0, "asc"]
  ]
});

HTML Code :

<div class="box-body">
  <div class="order-column">
    <table id="dtslider" class="table table-striped table-bordered">
      <thead class="dt-right">
        <tr>
          <th>id</th>
          <th>Judul Panel</th>
          <th>Isi Panel</th>
          <th>Actions</th>
        </tr>
      </thead>
      <tbody></tbody>
    </table>
  </div>
</div>
<!-- /.box-body -->

The output : enter image description here In image ouput there are strong at row2 and pre at row 3. I need to remove all html tags at the output. I already try something like sType and createdrow, but still no result. maybe because i am still new at DataTables and JavaScript. Can someone help me?

Edit (more code) :

getdata_slider :

public function getdata_slider()
	{
		$column = 'idHome, jdlHome, isiHome';
		$id     = 'idHome';
		$table  = 'home';
		$columnwhere = 'ketHome';
		$key 	= '1';

		$this->Model_administrator->getDatatablesCustom2($column, $id, $table, $columnwhere, $key);
		echo $this->datatables->generate();
	}

getDatatablesCustom2 :

public function getDatatablesCustom2($column, $id, $table, $columnwhere, $key)
	{
		$this->load->library('Datatables');
		$this->load->helper('Datatables_helper');
		$this->datatables->select($column)->where($columnwhere, $key)
		->unset_column('file')
		->add_column('file','<a href="'.base_url("assets/uploads/$1").'">$1</a>', 'file')
		->add_column('Actions', get_buttons('$1'), $id)
		->from($table);
	}

Upvotes: 2

Views: 1965

Answers (2)

La Croix
La Croix

Reputation: 111

sType, createRow, and even columnRender didnt do anything for me. I don't know the fault is in library, jquery, or the stupid me (70% fault in the latter of course.).

but, thankfully, i found edit_column at library function.

my code now look something like this :

public function getDatatablesCustom2($column, $id, $table, $columnwhere, $key)
	{
		$this->load->library('Datatables');
		$this->load->helper('Datatables_helper');
		$this->datatables->select($column)->where($columnwhere, $key)
		->unset_column('file')
		->edit_column('isiHome', '$1', 'strip_tags(isiHome)')
		->add_column('file','<a href="'.base_url("assets/uploads/$1").'">$1</a>', 'file')
		->add_column('Actions', get_buttons('$1'), $id)
		->from($table);
	}

thanks for all the pointer and help :)

Upvotes: 1

MBaas
MBaas

Reputation: 7530

I would use the columns.render-Option to manipulate the data before it is being rendered.

Upvotes: 1

Related Questions