Uncaught Type error when trying to create a dropdown
Uncaught Type error when trying to create a dropdown
steven.stenzel
Posts: 9Questions: 3Answers: 0
I have managed to get the editor working with sever tables and joins, and I thought I would try to implement the dropdown option for some user friendliness, and how I am getting
Uncaught TypeError: Cannot use 'in' operator to search for '9' in json.users jquery.js:2
r jquery.js:2
m.extend.each jquery.js:2
labelValPair dataTables.editor.js:5121
fieldTypes.select.$.extend._addOptions dataTables.editor.js:5200
fieldTypes.select.$.extend.update dataTables.editor.js:5220
Editor.Field._typeFn dataTables.editor.js:422
that.(anonymous function) dataTables.editor.js:218
$.DataTable.initComplete datatest:60
(anonymous function) jquery.dataTables.js:5096
m.extend.map jquery.js:2
_fnCallbackFire jquery.dataTables.js:5095
_fnInitComplete jquery.dataTables.js:3248
(anonymous function) jquery.dataTables.js:3220
_fnBuildAjax.baseAjax.success jquery.dataTables.js:2380
j jquery.js:2
k.fireWith jquery.js:2
x jquery.js:4
b jquery.js:4
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Here is the php, i am currently calling it through laravel routing, and dynamically generating the columns from an array, to allow me to edit it quickly. This works fine with join tables and double join tables, but I'm getting the error with dropdowns.
```php
<?php use DataTables\Editor, DataTables\Editor\Field, DataTables\Editor\Format, DataTables\Editor\Join, DataTables\Editor\Validate; class DataTablesController extends \BaseController{ private $Data = array(); private function getData(){ $this->Data = array( "columns"=>array( array("column"=>"listings.id", "name"=>"Listing ID", "type"=>"readonly"), // array("column"=>"listings.listing_type", "name"=>"Listing Type", "type"=>""), array("column"=>"listings.creating_user", "name"=>"users", "type"=>"select"), array("column"=>"users.id", "name"=>"User Id", "type"=>"hidden"), array("column"=>"users.email", "name"=>"Owner Data", "type"=>"data"), // array("column"=>"listings.property_id", "name"=>"LProperty ID", "type"=>"hidden"), //array("column"=>"properties.id", "name"=>"Property ID", "type"=>"hidden"), // array("column"=>"properties.size_type", "name"=>"Size Type", "type"=>""), // array("column"=>"properties.address_id", "name"=>"PAddress ID", "type"=>"hidden"), // array("column"=>"addresses.id", "name"=>"Address ID", "type"=>"hidden"), // array("column"=>"addresses.street_name", "name"=>"Street Name", "type"=>"") ), "joins"=>array( // array("table"=>"properties", "key"=>"id", "join"=>"listings.property_id"), // array("table"=>"addresses", "key"=>"id", "join"=>"properties.address_id"), array("table"=>"users", "key"=>"id", "join"=>"listings.creating_user") ) ); } public function index(){ $this->getData(); //$_POST = Input::all(); // foreach($_POST as $key=>$value){error_log($key.' = '.$value);} // foreach($_GET as $key=>$value){error_log($key.' = '.$value);} //Try entering this page with a random get string - this needs to be fixed somehow if(!empty($_GET) || !empty($_POST)){ require_once($_SERVER['DOCUMENT_ROOT'].'/../app/lib/datatables/DataTables.php'); $columns = array(); //Create Columns into array foreach($this->Data['columns'] as $column){$columns[] = Field::inst($column['column']);} $editor = Editor::inst( $db,'listings')->fields($columns); foreach($this->Data['joins'] as $join){ $editor->leftJoin($join['table'],$join['table'].'.'.$join['key'],'=',$join['join']);} $out = $editor->process($_POST)->data(); //if(!isset($_POST['action'])){ foreach($this->Data['columns'] as $column){ if($column['type'] == 'data'){ $column['table'] = explode(".",$column['column']); $column['column'] = $column['table'][1]; $column['table'] = $column['table'][0]; error_log('column["column"] = '.$column['column']); $out[$column['table']] = $db->selectDistinct($column['table'],'id as value, '.$column['column'].' as label')->fetchAll(); } } //} echo json_encode( $out); }else{ ?>
<html>
<head>
<title> Corporate Back Office - Data Admin </title>
<!-- DataTables, TableTools and Editor CSS -->
<link rel="stylesheet" type="text/css" href="/assets/datatables/media/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="/assets/datatables/extensions/TableTools/css/dataTables.tableTools.css">
<link rel="stylesheet" type="text/css" href="/assets/datatables/extensions/Editor-1.3.2/css/dataTables.editor.css">
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css">
<!-- jQuery, DataTables, TableTools and Editor Javascript -->
<script type="text/javascript" src="/assets/datatables/media/js/jquery.js"></script>
<script type="text/javascript" src="/assets/datatables/media/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="/assets/datatables/extensions/TableTools/js/dataTables.tableTools.js"></script>
<script type="text/javascript" src="/assets/datatables/extensions/Editor-1.3.2/js/dataTables.editor.js"></script>
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/../app/views/partials/scripts.php');?>
<script type="text/javascript" language="javascript" class="init">
var editor;
}
<?php > ``` ?>Hi,
The thing that immediately stands out is:
You are passing in a string - not the value of
json.users
. Remove the quotes and, hopefully it will start working.Allan
Perfect Allan, didn't immediately jump out yesterday, but i'm sure it will become obvious when I get used to your library. ;)