volosoft / jtable

A JQuery plugin to create AJAX based CRUD tables.
http://www.jtable.org
1.1k stars 505 forks source link

Jtable Fields coming from database #1133

Open rheinzlabzher02 opened 10 years ago

rheinzlabzher02 commented 10 years ago

Im using jquery jtable for my website, the jtable runs fine and there's no problem. But now I needed the fields to be dynamic. I mean, for example if the admin adds a subject on the table tblsubject on my db, it should be automaticaly added to fields on jtable init. Is that possible even possible?

I created a php code, actually the code is created with the help of other members here. that outputs the same format of fields in jtable :

General:{
title: 'General',
width: '30%',
list:false
}

-----> the php code:

$cons = mysql_query( 'SELECT Subject FROM tblsubject' );
$total_rows = mysql_num_rows($cons);
while($row = mysql_fetch_array($cons)) {
   $array[]= $row['Subject']. ': { <br/> title: \' '.$row['Subject'].' \',<br/> width: \'20% \' <br/>}';
}
$variable = implode(',<br/>', $array);

But when I include it on jtable

Fields{ <?php echo $variable; ?>}

the table didn't display.Can you please tell me what I'm doing wrong. I really need it :D Thank you fellaz. All ideas and comments are welcome.

jeff-liberty commented 10 years ago

I am doing something similar to your request but using C# and an MVC site. I am building the jtable.js file with the columns dynamically and downloading it via an ajax call. A call is then made from jtable to my controller action where it builds the list json result. It works good overall but there looks like there is a bug in the jtable code when I try to load a new jtable in the same div as the old one. I hope to get a response about this issue or fix it myself soon. Here is my issue with my code that I am using. https://github.com/hikalkan/jtable/issues/1050

Hope this helps.

rheinzlabzher02 commented 10 years ago

Hi sir @jeff-liberty. i've already fix it, but sadly mine is in PHP code.. this is the old code:

$array[]= $row['Subject']. ': { <br/> title: \' '.$row['Subject'].' \',<br/> width: \'20% \' <br/>}';

just remove the "
" tag like this, and it will work fine, just don't forget to change the value of the $_POST[''] or whatever you use in C#. I'm not that familiar with that language. Even if I wanted to help, sorry.

$array[]= $row['Subject']. ': {  title: \' '.$row['Subject'].' \', width: \'20% \' }';

Hmmm, may Sir @hikalkan can solve your problem or can find a fix about the bug you're talking about. :smile: