-3

I'm trying to put a jQuery pluin in a module which I have developed. When I do it, it doesn't work. The code where I put this labels is this:

<?php

   // no direct access
   defined('_JEXEC') or die;
   JHtml::_('stylesheet', JUri::root . 'modules/mod_k2_users/tmpl/Default/DataTables-1.10.4/media/css/jquery.dataTables.css');
   JHtml::_('script', JUri::root . 'modules/mod_k2_users/tmpl/Default/DataTables-1.10.4/media/js/jquery.dataTables.js');
   JHtml::_('jquery.framework');
   $params = K2HelperUtilities::getParams('com_k2');
   $limitstart = JRequest::getInt('limitstart');
?>

<script>
   jQuery(document).ready(function() {
   jQuery('#tUsuarios').dataTable( {
    "searching":true,
    "paging":   true,
    "ordering": true,
    "info":     false
   } );
 } );
</script>



 <div id="k2ModuleBox<?php echo $module->id; ?>" class="k2UsersBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">
    <table id="tUsuarios" class="display">
     <thead>
      <tr>

        <th>Nombre</th>
        <th>Nivel</th>
        <th>País</th>
        <th>Votos</th>
        <th>Skype</th>
        <th>Hangaout</th>
        <th>Facetime</th>
        <th>Correo</th>

     </tr>
    </thead>
   <tbody>

       <?php foreach($users as $key=>$user): 


    ?>
      <tr class="<?php echo ($key%2) ? "odd" : "even"; if(count($users)==$key+1) echo ' lastItem'; ?>">
       <td> 
        <?php if($userName): ?>
        <a class="ubUserName" rel="author" href="<?php echo $user->link; ?>" title="<?php echo K2HelperUtilities::cleanHtml($user->Nombre); ?>">
            <?php echo $user->Nombre; ?>
        </a>
        <?php endif; ?>
     </td>
     <td>

     </td>
     <td>
        <?php if($userName): ?>
        <a class="ubUserName" rel="author" href="<?php echo $user->link; ?>" title="<?php echo K2HelperUtilities::cleanHtml($user->Nivel); ?>">
            <?php echo $user->Nivel; ?>
        </a>
        <?php endif; ?>
     </td>
     <td>
        <?php if($userName): ?>
        <a class="ubUserName" rel="author" href="<?php echo $user->link; ?>" title="<?php echo K2HelperUtilities::cleanHtml($user->Pais); ?>">
            <?php echo $user->Pais; ?>
        </a>
        <?php endif; ?>
     </td>
     <td>
        <?php if($userName): ?>
        <a class="ubUserName" rel="author" href="<?php echo $user->link; ?>" title="<?php echo K2HelperUtilities::cleanHtml($user->Nombre); ?>">
            <?php echo $user->Nombre; ?>
        </a>
        <?php endif; ?>
     </td>
     <td>
        <?php if($userName): ?>
        <a class="ubUserName" rel="author" href="<?php echo $user->link; ?>" title="<?php echo K2HelperUtilities::cleanHtml($user->Skype); ?>">
            <?php echo $user->Skype; ?>
        </a>
        <?php endif; ?>
     </td>
     <td>
        <?php if($userName): ?>
        <a class="ubUserName" rel="author" href="<?php echo $user->link; ?>" title="<?php echo K2HelperUtilities::cleanHtml($user->Google); ?>">
            <?php echo $user->Google; ?>
        </a>
        <?php endif; ?>
     </td>
     <td>
        <?php if($userName): ?>
        <a class="ubUserName" rel="author" href="<?php echo $user->link; ?>" title="<?php echo K2HelperUtilities::cleanHtml($user->Facebook); ?>">
            <?php echo $user->Facebook; ?>
        </a>
        <?php endif; ?>
     </td>
      <td>
        <?php if($userName): ?>
                <span class="ubUserName" rel="author" title="<?php echo K2HelperUtilities::cleanHtml($user->Email); ?>">
                <?php echo $user->Email;?>
            </span>
            <?php endif; ?>
     </td>



    </tr>
    <?php endforeach; ?>
</tbody>    
</table>

What I'm doing wrong?. Thanks so much

  • What exactly does not work? BTW defined('_JEXEC') or die; should be on the top of file. – Dmitry Rekun Feb 2 '15 at 7:11
  • This jquery plugin should sort a table.It's the table jquery which you can see here: datatables.net, and just I see the css, not more thins as on the website appears.Thanks – zoit Feb 2 '15 at 7:13
  • Are you saying that jquery.dataTables.js in not included? Can you provide the link to the page where do you use this module? Also I think that you do not need to include jquery.js - your template includes it. – Dmitry Rekun Feb 2 '15 at 7:27
  • The link it's this: rmh.citafgsr.info/index.php/servicios/intercambio-lingueistico – zoit Feb 2 '15 at 7:29
1

You've made a mistake in your code.

You're using jquery instead of jQuery. @Dmitry has already showed you the code you need to use which you could have copied ans pasted so I'm not sure how that went wrong.

jQuery(document).ready(function() {
    jQuery('#tUsuarios').dataTable( {
        "searching":true,
        "paging": true,
        "ordering": true,
        "info": false
    });
});

I would also suggest you import your CSS and JS files correctly, so replace:

<link rel="stylesheet" type="text/css" href="http://rmh.citafgsr.info/modules/mod_k2_intercambios/tmpl/Default/DataTables-1.10.4/media/css/jquery.dataTables.css">

<script type="text/javascript" charset="utf8" src="http://rmh.citafgsr.info/modules/mod_k2_intercambios/tmpl/Default/DataTables-1.10.4/media/js/jquery.dataTables.js"></script>

with:

<?php
    JHtml::_('stylesheet', JUri::root . 'modules/mod_k2_intercambios/tmpl/Default/DataTables-1.10.4/media/css/jquery.dataTables.css');
    JHtml::_('script', JUri::root . 'modules/mod_k2_intercambios/tmpl/Default/DataTables-1.10.4/media/js/jquery.dataTables.js');
?>

Please read the Joomla documentation before doing things else you will run into more problems and get a better understanding of things

| improve this answer | |
0

I am suggesting you to do the following:

  1. Move defined('_JEXEC') or die; to the top of your file.
  2. Do not include jquery.js in your module, because your template already includes it. You should also disable duplicate jQuery inclusion in your template. If you watch the source code of your page you will see that jquery.js in included several times.
  3. Try to change $ in your script to jQuery, like this:

<script>
  jQuery(document).ready(function() {
     jQuery('#tUsuarios').dataTable( {
        "searching":true,
        "paging":   true,
        "ordering": true,
        "info":     false
     });
  });
</script>
| improve this answer | |
  • I don't understand the 3rd point – zoit Feb 2 '15 at 9:44
  • What exactly? Just change $ to jQuery in your JS code. – Dmitry Rekun Feb 2 '15 at 9:52
  • Exactly, if this code it's between <script>, Must I keep these labels?. Regards – zoit Feb 2 '15 at 9:55
  • Keep everything, just change $ to jQuery in your code between <script> :) – Dmitry Rekun Feb 2 '15 at 9:56
  • It doesn't work :( – zoit Feb 2 '15 at 10:05
0

I am seeing that your js and css files are located in tmpl(template folder),

try keeping them in separate folder

and another thing is that did u intentionally made folder name in upper case ?
like

Default instead of default ?

try changing folder name in lowercase, sometime it becomes a huge issue in server.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.