How to open Codeigniter view from Editor?

How to open Codeigniter view from Editor?

dhDTforwebdhDTforweb Posts: 27Questions: 6Answers: 0

I made a site with Codeigniter and Datatables/Editor and it is great.
I followed this tutorial http://ci.dubbel16.nl/index.php/2015/12/22/codeigniter-with-datatables-and-editor/
It wasn't hard because that site reads from just one database table.

My next project has three levels of related tables:
Projects
Buildings (each project has many buildings, each building belongs to one project)
Equipment (each building has many pieces of equipment, each equipment belongs to one building)
Foreign keys of the parent table are stored in the child table.

I want to set up a page to view Projects - and be able to click on a row to go to the Buildings/View page (using Codeigniter's controller/method system) to see the buildings that belong to that project, by passing the project_id and querying the buildings table for matches.

So all I think I need to do is open the view page while passing the project_id.

In Codeigniter I can do somthing like
<a href="<?php echo site_url('building/view/'.$item['bldgid']); ?>"><?php echo $item['bldgname']; echo ", " ?></a>

With Editor I tried (haven't added the parameter yet)
var editor;
var table;
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
.........
} );
table = $('#example').DataTable( {
.........
} );
$('#example').on( 'click', 'tbody td', function () {
$.post('[Building/index', function(){});
});

The 'on click' function works. I tested it with alert windows.
The console returns
jquery-3.3.1.js:9600 XHR finished loading: POST "http://localhost/index.php/Building/view".
but the page doesn't change.

Seems like this should be easy but I can't get the syntax right.
Or am I missing something fundamental?
Thanks for any help!

Replies

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770
    edited August 2018

    I'm not familiar with Codeigniter so can't help there. This blog about Parent / Child tables may help:
    https://datatables.net/blog/2016-03-25

    If you aren't using Editor you can ignore those parts of the config.

    Edit: I see by the title you are using Editor :smile:

    Kevin

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    $.post(...) just makes an Ajax request to get the data from the URL given. It won't redirect the page. You would use window.location.href for that.

    However, I think what might be better here is just to have a link in the table which you can do using columns.render.

    Allan

  • dhDTforwebdhDTforweb Posts: 27Questions: 6Answers: 0

    That works! Thanks, Allen. Love your software

This discussion has been closed.