Appendgrid - getting grid data as a JSON object instead of normal serialization

In the example here, how can I get grid data as JSON?

Link Link

JQuery Serialize works, but it would be nice if I could get each line as a JSON object, so I can parse the data.

+8
javascript jquery
source share
3 answers

You can use the .appendGrid('getAllValue') function to get the grid data as javascript objects. You can parse them directly or encode them as JSON.

Example:

var data = $('#tblAppendGrid').appendGrid('getAllValue') returns an array in which each element is data from one table as an object.

data[0] will be the first row.

JSON.stringify(data) will be a JSON string with all the data from your table

+3
source share

You can create an element at runtime according to the length of the JSON object that you should use for each or a simple looping cycle and iterating the json data to length.

Like:

  for(var i=0; i<=json_object.length; i++) { console.log(json_object.user[i].name); var ele_block = document.createElement('div'); $(ele_block).addClass("block"+i); ele_block.appendChild(block_name); $("#name_block").append(ele_block); } 

Create an element to which the newly created data will be added.

 <div id="name_block"></div> 
0
source share

You can simply use jQuery Serialize to get the serial string, and then use the uri_decoder helper function to decode it into Object.

 var decode, seriesed, uri_decoder; seriesed = "a=1&b=2&c=3&d=4&e=5"; uri_decoder = function(component_unpacker) { if (component_unpacker == null) { component_unpacker = (function(s) { return s; }); } return function(str) { var d, i, j, k, len, ref, ref1, ref2, s, v; d = {}; ref1 = (ref = str.match(/[^?=&]+=[^&]*/g)) != null ? ref : []; for (i = 0, len = ref1.length; i < len; i++) { s = ref1[i]; ref2 = s.match(/([^=]+)=(.*)/), j = ref2.length - 2, k = ref2[j++], v = ref2[j++]; d[decodeURIComponent(k)] = component_unpacker(decodeURIComponent(v)); } return d; }; }; decode = uri_decoder(); console.log(json(decode(seriesed))); 

try this code here

This resource is provided by this project.

-one
source share

All Articles