i using org.codehaus.jackson.JsonGenerator to show my data but i could not be shown in Html
i using org.codehaus.jackson.JsonGenerator to show my data but i could not be shown in Html
peterrezaee
Posts: 6Questions: 1Answers: 0
i using org.codehaus.jackson.JsonGenerator to show my data but i could not be shown in Html
this is my data
public static ArrayList<String> mactx = new ArrayList<String>();
i use getter and setter.
here is my json
jgen.writeStartObject();
jgen.writeStringField("m",list.getM().toString() );
jgen.writeEndObject();
and my html code
function loadtransfromTable() {
transfromTable = $('#tableTX').DataTable({
responsive: true,
searching: false,
lengthChange: false,
scrollX: true,
paging: false,
order: [[ 2, 'asc' ], [ 4, 'asc' ]],
ajax : {
url : "http://" + ipaddress + ":" + restport + "/shown/json",
dataSrc: ''
},
columns : [
{data: 'm'}
]
});
$.ajax({
url : "http://" + ipaddress + ":" + restport + "/shown/json",
success: function (links) {
console.log(links);
}
});
}
everything works fine, table id is correct, link is correct , name columns too, but html don't show anything when it run
i want show m in my table ,
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
What is the actual data return from the ajax request?
Kevin
@kthorngren
it suppose to return list of ip adress like "[192.168.1.13, 192.168.1.14]"
i think problem is can not read Array
in commend line :
curl http://127.0.0.1:8080/shown/json | python -m json.tool
data shown as > "m": "[192.168.1.13, 192.168.1.13]",
Can you use the debugger and let us know the debug code so we can see the table setup please?
Allan
@allan
http://debug.datatables.net/okuset
You will need to restructure the returned data so that each array element contains one row. Here is the documentation explaining the data structure for an array of objects:
https://datatables.net/manual/data/#Objects
I think it would be best to change the server code to return the structure Datatables is expecting. If you can't do that then you can manipulate the return data to change the structure before applying it to Datatables.
Kevin
@kthorngren
thanks to you, but it can't not be possible cause rows number uncountable but column are fix, what do you means
like change data return Array to Strings,.. ?!
To make sure I understand, you current JSON data looks like this sample showing 2 of your rows:
You are unable to change your server script to provide the rows in this format:
If you are unable to change your server script then you will need to modify the returned data to match the second format above. One option is to move the ajax request from the Datatables init code and run it before initializing Datatables. This is an example I did for something else but it will show you one way to get the ajax data.
http://live.datatables.net/fafuyeyu/1/edit
This line
data = JSON.parse(data);
is getting the JSON data. In your case you will need to loop through your data and change the structure. There may be built in Javascript functions to do some of the work, I'm not sure.Kevin
@ i notice my fault about data i change them,but still i have same problem
http://debug.datatables.net/ulasop
what this means?
Your JSON format looks ok:
Except I think you need to put it into an array as shown here:
https://datatables.net/manual/data/#Objects
I think it should look like this:
Kevin
@kthorngren
thanks so much
i should add jgen.writeStartArray(); to first of my JSON code
that make it look like array
Don't worry about that in the debugger. Its a legacy thing for 1.9 support.
Great to hear you've got it working with Kevin's help
Allan