I'm very interested in integrating a new and fascinating JQUERY plugin called JTABLE.
This is a new plugin developed by Halil İbrahim Kalkan (http://www.jtable.org/).
I have a question in this context. In the pagecontroller, there is a custom script with the JQuery code.
At a certain point, you have to pass the action parameters, these are the controllers who will perform the
action with the db. For this example I just have the list action. In my controller, there is a function defined, showdata(),
which will rely upon the sapphire framework for collecting the data out of the dataobjects and return it in JSON format.
Might be a simple question for all the specialists on this forum, but how do I address this function (showdata() ) from my
customscript ? Apparently, 'window.location.href.showdata' wont work.
<?php
class JTableExample extends Page{
static $has_one = array (
'People' => 'People'
);
}
class JTableExample_Controller extends Page_Controller{
public function init(){
parent::init();
Requirements::javascript("mysite/jtable/jquery.jtable.js");
Requirements::javascript("mysite/jtable/jquery.jtable.min.js");
Requirements::javascript("sapphire/thirdparty/jquery/jquery.js");
Requirements::javascript("sapphire/thirdparty/jquery/jquery-ui/jquery-ui-1.8rc3.custom.js");
Requirements::customScript("
$(document).ready(function () {
$('#PersonTableContainer').jtable({
title: 'Table of people',
actions: {
listAction: 'window.location.href.showdata'
},
fields: {
PersonId: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Author Name',
width: '40%'
},
Age: {
title: 'Age',
width: '20%'
},
RecordDate: {
title: 'Record date',
width: '30%',
type: 'date',
create: false,
edit: false
}
}
});
$('#PersonTableContainer').jtable('load');
}) (jQuery);
");
}
function showdata(){
return json_encode(DataObject::get('People'));
}
}