Regarding row_details example.

Regarding row_details example.

jQuery_userjQuery_user Posts: 27Questions: 0Answers: 0
edited October 2010 in General
Hello,

I am using the row_details example in my project.
http://datatables.net/examples/api/row_details.html

In my case, I have to show filtered rows from an array (stored in the session) in the row details.
This array consists of objects (of class X)

So far, I can alert and get the size of the array in the function fnFormatDetails ( oTable, nTr )

But when I print the array, I get nulls.

Is this possible?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I don't see why not - but I don't know how you are getting the array in question, so atm I can't help too much. Perhaps you can post your code please? How are you getting the session (?) array?

    Allan
  • jQuery_userjQuery_user Posts: 27Questions: 0Answers: 0
    I am working on a JSP/servlet/bean application

    The servlet stores the array in the session.

    The JSP has access to this array.

    Here is my code:
    [code]
    function fnFormatDetails ( oTable, nTr )
    {
    var aData = oTable.fnGetData( nTr );
    var sOut = '';

    <%
    ArrayList lines = (ArrayList) getSession().getValue("resultLines");
    LineItem[] lineArray = new LineItem[lines.size()];
    int lineSize = lineArray.length;
    %>

    alert("Array: "+<%=lineArray%>);


    //sOut += 'Rendering engine:'+aData[1]+' '+aData[4]+'';
    //sOut += 'Link to source:Could provide a link here';
    //sOut += 'Extra info:And any further details here (images etc)';
    sOut += '';

    return sOut;
    }
    [/code]
    When I click on the row details, I see the array with all nulls.

    This array is a custom object with around 10 attributes (along with getters/setters).

    How can I realize this array on the client side using javascript, so I can print this array as a table.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Isn't that array going to be different for every row in the table? So you need access to the information in the array for each row - where as I guess the code above will only give you access to one row (if it were working) since it is rendered on the server, and not the client (i.e. right click 'view source' on your page, and you'll see the generated html).

    Perhaps what is needed, is the information in your array is put into the html table with hidden columns - much like I've done with my example. Another option is that you could create a static Javascript array of information and look that up for each row in the table.

    Allan
  • jQuery_userjQuery_user Posts: 27Questions: 0Answers: 0
    edited October 2010
    I tried following code:

    [code]
    <%
    ArrayList lines = (ArrayList)getSession().getValue("resultLines");

    LineItem[] lineItems = (LineItem[]) lines.toArray(new LineItem[lines.size()]);


    if(lineItems != null) { %>

    var linesJS = new Array(<%
    for(int i = 0; i < lineItems.length; i++) {
    out.print("\""+lineItems[i]+"\"");
    if(i+1 < lineItems.length) {
    out.print(",");
    }
    }
    %>);

    <% } %>

    alert("array: "+ linesJS);

    [/code]

    when I view source, it has random garbled values in the "linesJS" array, as I am copying an Object Array into var Array.

    Is it possible to create an array of corresponding javascript objects?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    That's a question for a JSP forum I think - I've not used JSP myself so can't be of much help :-)

    Allan
  • jQuery_userjQuery_user Posts: 27Questions: 0Answers: 0
    Hi Allan,

    I haven't worked much with javascript objects. This all boils down to declaring an array of custom objects, similar to this:

    [code]var myCars=new Array("Saab","Volvo","BMW");[/code]

    Can you provide syntax, or a simple example array with say 2 objects (properties: x, y)

    Thanks
This discussion has been closed.