Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.
  $(function() {
    function log( message ) {
      $( "<div>" ).text( message ).prependTo( "#log" );
      $( "#grille" ).scrollTop( 0 );
    }
    $( "#my_ac" ).autocomplete({
      source: function( request, response ) {
        $.ajax({
          url: "<?php echo url_for('jsonfile') ?>",
          dataType: "json",
          data: {
            limit: 100,
            q: request.term
          },
          success: function( data ) {
            response( $.map( data.images, function( item ) {
              return {
                label: item.nom,
                image: item.image,
                id: item.id
              }
            }));
          }
        });
      },
      minLength: 3
    })

    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
      $('#grille_table').append( '<tr><td><a href="/add/' + item.id + '"><img src="/upload/' + item.image + '" width="100" height="100" title="'+ item.label +'"></a></td><td>'+ item.label +'</td></tr>' );
      return $( "" )
    };
  });

So this is an autocomplete jquery script, I try to display the resut in a table instead of the select field which is the default behaviour but I dont really understand the renderItem method and I still have some graphics issue (pic)...Any idea how the method works and how to have better result with it ?

Result

share|improve this question
add comment

1 Answer

_renderItem should return an element so the code should look more or less like this:

return $('<tr><td><a href="/add/' + item.id + '"><img src="/upload/' + item.image + '" width="100" height="100" title="'+ item.label +'"></a></td><td>'+ item.label +'</td></tr>')

though there will be a problem with that, because autocomplete uses a ul element as the menu wrapper so you'll need to change the ul (this may help - autocomplete uses the menu ui widget)

I'd recommend to stick with the ul though (more semantic) and just use css to achieve a table like layout

share|improve this answer
 
thx I'm gonna look at that –  krifur May 2 '13 at 13:09
 
in the jquery link you just post I think there s an option that can do the job (, menus: "div.menuElement".) basically if I understand well it's to append the result of the menu in another structure then the <ul><li> one...But for now I don't know how to achieve this with my piece of code... –  krifur May 2 '13 at 15:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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