Changing display type based on file type.
Changing display type based on file type.
classic12
Posts: 228Questions: 60Answers: 4
Hy guys,
I am using the editor successfully ( amazed at how much you can do with it).
I am upload image / pdf / txt and xls files to my server.
I now need to show these in a datatable.
I use
"data": "web_path",
"render": function ( data)
{
return '<img src="'+'http://toolfolks.com'+data+'" style="height:50px;width:50px;"/>'
}
which is fine for images & pdf.
If the file is not image type how do I set the cell to show the filename and be downloadable. IE they click on it and it down loads.
Cheers
Steve Warby
This discussion has been closed.
Answers
Do you have the information telling you want the file type is in the row? If so, you can access that using the third parameter passed into
columns.render
. Then use a simpleif
condition to sent out the correct HTML.Allan
Thanks Allan,
I'm nearly there.
I am trying this approach.
but it fails on the push statement.
I would eventually have another field with a type of 'Image' or 'other'.
I presume I then run an if conditions here
Along the lines of . if data.type === image ( show image) if not change to link.
Cheers
Steve Warby
It would probably be
row.type
sincedata
there will beweb_path
, and you would arguments two and three to thecolumns.render
option, but that's the basic idea.I'm not clear on what
dataReturned
is. If thepush
is failing, it suggestsdataReturned[i]
is not an array.Allan
Hi allan,
where would I place the code as I am changing the values of the columns.
It doesn't allow me to add any code within the options
Cheers
Steve Warby
Where is this stuff being executed?
If you want to add additional information that is present in the server, to the data that is sent to the client-side, you'd need to do it in the server-side script.
Allan
Hi Allan,
been working late 4 am to try and update our existing apps. Decided to finish early but went to bed with Ipad and started reading the blogs and docs. This product is awesome......
On the client I loop the returned data ( modification of user, users_files, files)
So What I have is a new array that has the data as
'quoteID' :'1','web_path' :'xxx.com.image.jpg', 'web_path1' :'xxx.com.image1.jpg, 'web_path2' :'xxx.com.spreadsheet1.xls
So the columns options I have:
So I need to accoplish the following
So I'm not sure where I can put this logic on the client end.
Can someone do some 'Wizadry' to make it happen..
Cheers
Steve Warby
2) This should probably be enough:
3) Perhaps doing a similar extension check would do:
Given that you have the same rendering function 8 times, it would probably be best to set it using
columnDefs
, so you don't need to repeat it. Keep thecolumns.data
option in thecolumns
though, so each column refers to its own unique data.Allan
Thanks allan,
I tried the following ( I struggle knowing where to 'put things' ) so hopefully it's something simple.
```
columns: [
I get
'Unexpected token '.'. Expected a ')' or a ',' after a parameter declaration'
on the if statement.
You are missing the
render
parameter. I just showed the inside of what the function would look like - you need to have it inside the render function:Allan
Thanks again,
got that working
http://toolfolks.com/surplusAnywhere4/
I just need to hide the cell if the cell has undefined.
ie http://toolfolks.com/surplusAnywhere4/undefined
hide the ugly ' missing image '
Cheers
Steve Warby
Whoops one more.
I am using the ckeditor to edit one of the columns. So I can have a well formatted product description
This can become quite long so I need
To contain the row height and allow the client to scroll the cell.
When the response expands show th cell full height.
I founs this
but the row still expands
is probably what I would use for that.
Allan
Hi Allan,
the rows are still expanding.
http://toolfolks.com/surplusAnywhere5/
Cheers
Steve Warby
I don't see a
div
with the CSS suggested above:Allan
Hi Allan,
running blind here again...
I have added this to my projects CSS.
Does this mean dtDataChanged does not have the above.
Cheers
Steve Warby
It does have that CSS, but there is no
div
inside the cell for it to be applied to, so it can't be applied. You need adiv
element for that selector to pick anything up. A renderer could be used to add a div around the content.Allan
Hi Allan,
I've played around and can't get it working.
I presumed ( limited knowledge ) that this would work;
What is the correct syntax for this?
Also could I add the max height / scroller options at the same time.
Cheers
Steve Warby
You need to close the opening
div
:Allan