0

Hi frds I am trying to access the class which I have given to an image in jquery data-tables but there is no response on the browser-side.

Controller:

function load_image(){

    $this->datatables
        ->select('image')
        ->from('details')
        ->add_column('preview', '<img class="preview" width="100" height="100" src ="assets/Data/adv_images/$1">', 'image');

    echo $this->datatables->generate();
}

Using this controller I am able to load the image in the data-table. The following piece of code is loading the data-tables on the browser. When I click on the Image there is no alert dialouge box on the screen. Using web-console I am able to see the image class preview. Why I am not able to get the alert box on click.

$(document).ready(function() {   

          $('#example').dataTable
          ({
            'bProcessing'    : true,
            'bServerSide'    : true,
            'sAjaxSource'    : '<?php echo base_url();?>load_image',
            'iDisplayStart'  : 0,
            'fnServerData': function(sSource, aoData, fnCallback , oSettings)
            {     
              $.ajax
              ({
                'dataType': 'json',
                'type'    : 'POST',
                'url'     : sSource,
                'data'    : aoData,
                'success' : fnCallback,
                'cache'   : false
              });
            }
          });

        $('.preview').click(function(){
                        alert('hi');
                        })
        });
1
  • Can you try to place the .click(function) before the .dataTable() in your code. Commented May 11, 2014 at 11:44

1 Answer 1

1

You set the click eventhandler before the datatable wih the preview image is loaded.

Use this instead:

$('#example').on('click', '.preview', function() {
    alert('hi');
});

See the documentation for details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.