【问题标题】:How to strip tags in Jquery DataTables如何在 Jquery DataTables 中去除标签
【发布时间】:2016-04-20 10:18:17
【问题描述】:

我将 CodeIgniter 和 DataTables(link) 与库 IgnitedDatatables(link) 一起使用。

我不知道如何在 DataTables 中使用类似 strip_tags() 的东西。我只需要从 JSON 数据中删除所有 html 标记输出。

我的 JavaScript 代码:

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 代码:

<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 -->

输出: 在图像输出中,在第 2 行和第 3 行有强。我需要删除输出中的所有 html 标签。我已经尝试过类似 sType 和 createdrow 的方法,但仍然没有结果。也许是因为我还是 DataTables 和 JavaScript 的新手。有人可以帮我吗?

编辑(更多代码):

获取数据滑块:

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);
	}

【问题讨论】:

  • 我猜这是服务器端问题 - 您应该在 getdata_slider 函数中执行此操作
  • 你能给我更多的指针或例子我必须在 getdata_slider 做什么吗?我在刚才的帖子里写代码。

标签: javascript json codeigniter datatables


【解决方案1】:

我会使用columns.render-Option 在呈现数据之前对其进行操作。

【讨论】:

    【解决方案2】:

    sType、createRow 甚至 columnRender 都没有为我做任何事情。我不知道问题出在库、jquery 还是愚蠢的我(当然后者有 70% 的错误。)。

    但是,幸运的是,我在库函数中找到了 edit_column。

    我的代码现在看起来像这样:

    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);
    	}

    感谢所有的指针和帮助:)

    【讨论】:

      猜你喜欢
      • 2012-01-05
      • 2012-10-19
      • 2017-09-21
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      • 2011-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多