zepernick / Codeigniter-DataTables

CodeIgniter Library For Ajax Server Side DataTables 1.10 >
MIT License
93 stars 94 forks source link

Does your solution work with CI3 and HMVC ? #3

Closed jdriesen closed 9 years ago

jdriesen commented 9 years ago

I'm brandnew to this ... so sorry if my question sounds stupid ...

Regards,

Johnny

zepernick commented 9 years ago

Hi Johnny, Yes it works with CI 3. Here is a demo app using CI 3 that you can take a look at. I have not used it with HMVC so I cannot speak to that.

jdriesen commented 9 years ago

Thanks for your quick reply, @zepernick . I guess I'm doing smt fundamentally wrong, cause I'm having the same issue as mentioned in https://github.com/zepernick/Codeigniter-DataTables/issues/2 ...

But as told before, I'm rather new to PHP and classes ...

zepernick commented 9 years ago

can you paste you model in for the DataTable, and a snippet from your controller so I can see it?

jdriesen commented 9 years ago

Will do this first job in the morning (It's close to midnight here, and some family members are complaining :)

Thanks in advance for your help, @zepernick .

G'night,

Johnny

jdriesen commented 9 years ago

Hi Paul,

I THINK I found the error. I'm loading my model in the constructor of my Controller,and that doesn't seem to work. Based on the example you've sent me yesterday, I'm going to study a bit more.

Will keep you informed about my progress (later on today)

Grtz,

Johnny

jdriesen commented 9 years ago

Hi Gents,

Thanks for your quick reply, but I still can't make it work ... I'm receiving an error: 'invalid JSON response' ...

I will explain a bit the situation ... I've written a test application (CI3 HMVC) with 2 tables. Table 1: Persons Contains 100,000+ records. Fields: id, gender_id, name, description

Table 2: Genders Contains 3 records Fields: id, name, description

A simple join should do the trick, and should show me a table with fields: Person_id, Person_name, Person_description, Gender_id, Gender_name (on top of each column a search fields, but that shouldn't be a problem, I guess)

But, as told before... for one reason or another... generating the JSON doesn't work...

Can I kindly ask you to take a quick look at it ?

I've tried to add the complete source (+ SQL database) in attach. (but the file is too big) Can I send it to you in another way (Wetransfer should be a help ... pls provide me your email address ... mine = INFO at 3SN dot BE

PS.: FEEL FREE to use this demo app also on your website !! It contains FAKE data, and I guess it will help (and impress) a lot of other developers who are using CI3 and HMVC in combination with serverside loading and tons of records...

Thanks in advance for your reply,

Johnny

zepernick commented 9 years ago

Thanks Johnny, I would love to use it as a demo site. You can send it to paulz17 a t yahoo dot com. The model implementing the interface should not be loaded in the controller. The reason for this is that the interface is not available until the library is loaded. The library is aware of the model through the configuration and loads the model itself. I have a note in the example controller in the readme.

//Important to NOT load the model and let the library load it instead.  
      $this -> load -> library('Datatable', array('model' => 'state_dt', 'rowIdCol' => 'c.id'));

The bad json message is usually because of a error being thrown in the php and it is getting a php error page returned back instead of the JSON it is expecting.

Please go ahead and send your project over. We will get it all fixed up and post it as a example. Also, feel free to make recommendations to the documentation as to how I can make it more clear on how the library should be initialized in the controller.

Thanks,

Paul

jdriesen commented 9 years ago

Project sent via WeTransfer. In case additional info is needed, feel free to contact me.

Regards and thanks in advance,

Johnny

jdriesen commented 9 years ago

@zepernick :+1: Got it almost working, though not yet 100%. (column persons.name is not shown, probably cause there is also a column named 'name' in the genders table ...

Please see mail for further details...

Regards,

Johnny

jdriesen commented 9 years ago

@zepernick ... I guess my prob has smt to do with the definition of

public function appendToSelectStr() { return NULL; }

Though, to be honest... the documentation is not that clear about it ...

I really hope you can help,

Thanks in advance,

Johnny

zepernick commented 9 years ago

Johnny and I resolved this through email. Here is how to use appendToSelectStr() to alias duplicate column names.

public function appendToSelectStr() {
     return array(
        'person_name' => 'p.name',
        'gender_name' => 'g.name'
     );
}

In the javascript column definitions, use the $ to indicate you want to reference a column alias.

...
data: "$.person_name"
...