drop-down list with the choice
drop-down list with the choice
maxstd
Posts: 6Questions: 2Answers: 0
Hello friends!
Please help with the solution of problem:
I have a mysql table that has three fields -
id, parent_id, name
|id| | parent_id| | name |
---|---|---|
|1 | | | | store |
|2 | | | | cafe |
|3 | | 1 | | store_name1 |
|4 | | 1 | | store_name2 |
|5 | | 2 | | cafe_name1 |
|6 | | 2 | | cafe_name2 |
(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.test.php',
table: '#test',
fields:
[
{label: "pole1",name: "test.id",type: "select"},
{label: "pole2",name: "test.parent_id",type: "select"}
]
} );
var table = $('#test').DataTable( {
dom: 'Tfrtip',
ajax: 'php/table.test.php',
columns:
[
{data: "test.id"},
{data: "test.parent_id"}
],
select: true,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
} );
} );
}(jQuery));
include( "lib/DataTables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
Editor::inst( $db, 'test'' )
->fields(
Field::inst( 'id' )->options('test','id','name'),
Field::inst( 'parent_id' )->options('test','parent_id','name')
)
->process( $_POST )
->json();
here's my question:
when set in the pole1 (store or cafe), in pole2 put a value equal to its id
This discussion has been closed.
Answers
replay
So you want the options in the second list to change based on the value selected int he first list?If so, then the
dependent()
method is probably the best way to do this. You would need to write a script on the server-side that will get the data for the list based on the value submitted, and then return the options as JSON data so Editor can update the list of options.Regards,
Allan
Thanks for the quick response!
Do I understand correctly -
1 step:
create get_fields.php file
step 3:
add in my js file this code
or this metod is wrong?
Sorry Allan, but I can not understand how to relate these fields using dependent. I have tried only to show and hide, but no more.