Closed afagard closed 6 years ago
Ok, so Datatables can read an array or it can read an object. I still don't get why it is useful :) Sorry if I'm a bit slow with this one. But the IgnitedDatatables always seems to return something like:
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
}
Not:
[
"Tiger Nixon",
"System Architect",
"$320,800",
"2011/04/25",
"Edinburgh",
"5421"
]
While my code looks like this:
function dt() {
$('#testimonials').DataTable({
destroy: true,
processing: true,
serverSide: true,
pageLength: 5,
lengthMenu: [5, 10, 20, 50, 100],
autoWidth: false,
ajax: {
url: '/neou_cms/testimonials/get_table/',
type: 'POST'
},
columns: [
{data: 'checkbox', orderable: false, searchable: false},
{data: 'name'},
{data: 'created'},
{data: 'last_modified'},
{data: 'actions', orderable: false, searchable: false}
]
});
}
If you set column names in datatables, It returns it as objects
"columns": [
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "extn" },
{ "data": "start_date" },
{ "data": "salary" }
]
Remove this section and see what happens.
The code checks if the columns array has a name or a number as index .
It is a function for check the type of your columns and return true or false if this is numeric, but it can be a problem if the type of your column is string, but it is easy to fix, change the code in the function get_filtering to:
/**
* Generates a %LIKE% portion of the query
*
* @return mixed
*/
private function get_filtering()
{
$mColArray = $this->ci->input->post('columns');
$sWhere = '';
$search = $this->ci->input->post('search');
$sSearch = $this->ci->db->escape_like_str(trim($search['value']));
$columns = array_values(array_diff($this->columns, $this->unset_columns));
if($sSearch != '')
for($i = 0; $i < (count($mColArray) - 1); $i++)
if ($mColArray[$i]['searchable'] == 'true' && !array_key_exists($mColArray[$i]['data'], $this->add_columns))
if($this->check_cType())
$sWhere .= $this->select[$mColArray[$i]['data']] . "::VARCHAR ILIKE '%" . $sSearch . "%' OR ";
else
$sWhere .= $this->select[$this->columns[$i]] . "::VARCHAR ILIKE '%" . $sSearch . "%' OR ";
$sWhere = substr_replace($sWhere, '', -3);
if($sWhere != '')
$this->ci->db->where('(' . $sWhere . ')');
// TODO : sRangeSeparator
foreach($this->filter as $val)
$this->ci->db->where($val[0], $val[1], $val[2]);
}
Thank you n1crack I understand it completely now.
I can see that it checks if column 0 is numeric. But why? I ask because I am rewriting portions of the core code and I don't understand its purpose. Is it a remnant from a previous datatable version that is meant to add support for backwards compatibility?