L.Geojson.ajax get multiple information in one point - ajax

I am building a web platform using HTML, CSS and Javascript. I used geojson data to spatially present the data. The geojson file is a point file with 11 points; however, each point have multiple rows in attribute table. I want to present the multiple information in the form of popup in the web platform.
My geojson file is like this (a part of it):
{
"type": "FeatureCollection",
"name": "spectral_library",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "ID": 1.0, "Sample_nr": "INOV01", "Spectrum_n": "INOV01_1", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602939.04, "Latitude": 4606832.31, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "White and yellowish", "Face_type": "Exposed", "Photo": "INOV01_1.jpg", "Raw_Spectr": "INOV01_1", "Processed_": "INOV01_1_CR", "Spectra_ab": "INOV01_1_abs_1.png", "Spectra__1": "INOV01_1_abs_2", "Spectra__2": "INOV01_1_abs_3", "Spectra__3": "INOV01_1_abs_4", "Spectra__4": "INOV01_1_abs_5", "Spectral_m": "Sericite/white mica" }, "geometry": { "type": "Point", "coordinates": [ -7.764631355723165, 41.606567474499826 ] } },
{ "type": "Feature", "properties": { "ID": 2.0, "Sample_nr": "INOV01", "Spectrum_n": "INOV01_2", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602939.04, "Latitude": 4606832.31, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "White", "Face_type": "Exposed", "Photo": "INOV01_2.jpg", "Raw_Spectr": "INOV01_2", "Processed_": "INOV01_2_CR", "Spectra_ab": "INOV01_2_abs_1", "Spectra__1": "INOV01_2_abs_2", "Spectra__2": "INOV01_2_abs_3", "Spectra__3": "INOV01_2_abs_4", "Spectra__4": "INOV01_2_abs_5", "Spectral_m": "Sericite/white mica; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764631355723165, 41.606567474499826 ] } },
{ "type": "Feature", "properties": { "ID": 3.0, "Sample_nr": "INOV01", "Spectrum_n": "INOV01_3", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602939.04, "Latitude": 4606832.31, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Yellowish and white", "Face_type": "Exposed", "Photo": "INOV01_3.jpg", "Raw_Spectr": "INOV01_3", "Processed_": "INOV01_3_CR", "Spectra_ab": "INOV01_3_abs_1", "Spectra__1": "INOV01_3_abs_2", "Spectra__2": "INOV01_3_abs_3", "Spectra__3": "INOV01_3_abs_4", "Spectra__4": "INOV01_3_abs_5", "Spectral_m": "Sericite/white mica; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764631355723165, 41.606567474499826 ] } },
{ "type": "Feature", "properties": { "ID": 4.0, "Sample_nr": "INOV01", "Spectrum_n": "INOV01_4", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602939.04, "Latitude": 4606832.31, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Black and white", "Face_type": "Exposed", "Photo": "INOV01_4.jpg", "Raw_Spectr": "INOV01_4", "Processed_": "INOV01_4_CR", "Spectra_ab": "INOV01_4_abs_1", "Spectra__1": "INOV01_4_abs_2", "Spectra__2": "INOV01_4_abs_3", "Spectra__3": "INOV01_4_abs_4", "Spectra__4": "INOV01_4_abs_5", "Spectral_m": "Smectite mineral (probable montmorillonite) mixed with cookeite; detected Fe2+ in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764631355723165, 41.606567474499826 ] } },
{ "type": "Feature", "properties": { "ID": 5.0, "Sample_nr": "INOV01", "Spectrum_n": "INOV01_5", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602939.04, "Latitude": 4606832.31, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "White and brown", "Face_type": "Exposed", "Photo": "INOV01_5.jpg", "Raw_Spectr": "INOV01_5", "Processed_": "INOV01_5_CR", "Spectra_ab": "INOV01_5_abs_1.png", "Spectra__1": "INOV01_5_abs_2.png", "Spectra__2": "INOV01_5_abs_3.png", "Spectra__3": "INOV01_5_abs_4.png", "Spectra__4": "INOV01_5_abs_5", "Spectral_m": "Sericite/white mica" }, "geometry": { "type": "Point", "coordinates": [ -7.764631355723165, 41.606567474499826 ] } },
{ "type": "Feature", "properties": { "ID": 6.0, "Sample_nr": "INOV02", "Spectrum_n": "INOV02_1", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602941.58, "Latitude": 4606824.22, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Yellowish", "Face_type": "Exposed", "Photo": "INOV02_1.jpg", "Raw_Spectr": "INOV02_1", "Processed_": "INOV02_1_CR", "Spectra_ab": "INOV02_1_abs_1", "Spectra__1": "INOV02_1_abs_2", "Spectra__2": "INOV02_1_abs_3", "Spectra__3": "INOV02_1_abs_4", "Spectra__4": "INOV02_1_abs_5", "Spectral_m": "White mica" }, "geometry": { "type": "Point", "coordinates": [ -7.764602270005769, 41.60649429499442 ] } },
{ "type": "Feature", "properties": { "ID": 7.0, "Sample_nr": "INOV02", "Spectrum_n": "INOV02_2", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz- Iron Oxide", "WGS84_Zone": "29N", "Longitude": 602941.58, "Latitude": 4606824.22, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "White, black and yellowish", "Face_type": "Exposed", "Photo": "INOV02_2.jpg", "Raw_Spectr": "INOV02_2", "Processed_": "INOV02_2_CR", "Spectra_ab": "INOV02_2_abs_1", "Spectra__1": "INOV02_2_abs_2", "Spectra__2": "INOV02_2_abs_3", "Spectra__3": null, "Spectra__4": null, "Spectral_m": "Illite (possibly mixed with montmorillonite)" }, "geometry": { "type": "Point", "coordinates": [ -7.764602270005769, 41.60649429499442 ] } },
{ "type": "Feature", "properties": { "ID": 8.0, "Sample_nr": "INOV02", "Spectrum_n": "INOV02_3", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz- Iron Oxide", "WGS84_Zone": "29N", "Longitude": 602941.58, "Latitude": 4606824.22, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Yellowish", "Face_type": "Exposed", "Photo": "INOV02_3.jpg", "Raw_Spectr": "INOV02_3", "Processed_": "INOV02_3_CR", "Spectra_ab": "INOV02_3_abs_1", "Spectra__1": "INOV02_3_abs_2", "Spectra__2": "INOV02_3_abs_3", "Spectra__3": "INOV02_3_abs_4", "Spectra__4": "INOV02_3_abs_5", "Spectral_m": "White mica; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764602270005769, 41.60649429499442 ] } },
{ "type": "Feature", "properties": { "ID": 9.0, "Sample_nr": "INOV02", "Spectrum_n": "INOV02_4", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz- Iron Oxide", "WGS84_Zone": "29N", "Longitude": 602941.58, "Latitude": 4606824.22, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Yellowish and black", "Face_type": "Exposed", "Photo": "INOV02_4.jpg", "Raw_Spectr": "INOV02_4.jpg", "Processed_": "INOV02_4_CR", "Spectra_ab": "INOV02_4_abs_1", "Spectra__1": "INOV02_4_abs_2", "Spectra__2": "INOV02_4_abs_3", "Spectra__3": "INOV02_4_abs_4", "Spectra__4": null, "Spectral_m": "Sericite/white mica; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764602270005769, 41.60649429499442 ] } },
{ "type": "Feature", "properties": { "ID": 10.0, "Sample_nr": "INOV03", "Spectrum_n": "INOV03_1", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz- Iron Oxide", "WGS84_Zone": "29N", "Longitude": 602947.62, "Latitude": 4606814.53, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Yellowish and black", "Face_type": "Exposed", "Photo": "INOV03_1.jpg", "Raw_Spectr": "INOV03_1", "Processed_": "INOV03_1_CR", "Spectra_ab": "INOV03_1_abs_1", "Spectra__1": "INOV03_1_abs_2", "Spectra__2": "INOV03_1_abs_3", "Spectra__3": "INOV03_1_abs_4", "Spectra__4": null, "Spectral_m": "Montmorillonite mixed with illite and/or kandite group mineral; detected Fe3+ in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764531465344857, 41.606406255838571 ] } },
{ "type": "Feature", "properties": { "ID": 11.0, "Sample_nr": "INOV03", "Spectrum_n": "INOV03_2", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602947.62, "Latitude": 4606814.53, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Brown and white", "Face_type": "Exposed", "Photo": "INOV03_2.jpg", "Raw_Spectr": "INOV03_2", "Processed_": "INOV03_2_CR", "Spectra_ab": "INOV03_2_abs_1", "Spectra__1": "INOV03_2_abs_2", "Spectra__2": "INOV03_2_abs_3", "Spectra__3": "INOV03_2_abs_4", "Spectra__4": null, "Spectral_m": "Illite mixed with kandite group mineral; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764531465344857, 41.606406255838571 ] } },
{ "type": "Feature", "properties": { "ID": 12.0, "Sample_nr": "INOV03", "Spectrum_n": "INOV03_3", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602947.62, "Latitude": 4606814.53, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Gray", "Face_type": "Exposed", "Photo": "INOV03_3.jpg", "Raw_Spectr": "INOV03_3", "Processed_": "INOV03_3_CR", "Spectra_ab": "INOV03_3_abs_1", "Spectra__1": "INOV03_3_abs_2", "Spectra__2": "INOV03_3_abs_3", "Spectra__3": null, "Spectra__4": null, "Spectral_m": "Illite mixed with kandite group mineral; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764531465344857, 41.606406255838571 ] } },
{ "type": "Feature", "properties": { "ID": 13.0, "Sample_nr": "INOV04", "Spectrum_n": "INOV04_1", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602957.46, "Latitude": 4606801.99, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Brown and white", "Face_type": "Exposed", "Photo": "INOV04_1.jpg", "Raw_Spectr": "INOV04_1", "Processed_": "INOV04_1_CR", "Spectra_ab": "INOV04_1_abs_1", "Spectra__1": "INOV04_1_abs_2", "Spectra__2": "INOV04_1_abs_3", "Spectra__3": "INOV04_1_abs_4", "Spectra__4": null, "Spectral_m": "Illite mixed with kandite group mineral; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764415557280173, 41.606292061781438 ] } },
{ "type": "Feature", "properties": { "ID": 14.0, "Sample_nr": "INOV04", "Spectrum_n": "INOV04_2", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602957.46, "Latitude": 4606801.99, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "White and black", "Face_type": "Exposed", "Photo": "INOV04_2.jpg", "Raw_Spectr": "INOV04_2", "Processed_": "INOV04_2_CR", "Spectra_ab": "INOV04_2_abs_1", "Spectra__1": "INOV04_2_abs_2", "Spectra__2": "INOV04_2_abs_3", "Spectra__3": null, "Spectra__4": null, "Spectral_m": "White mica/illite mixed with orthoclase; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764415557280173, 41.606292061781438 ] } },
{ "type": "Feature", "properties": { "ID": 15.0, "Sample_nr": "INOV04", "Spectrum_n": "INOV04_3", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz- Iron Oxide", "WGS84_Zone": "29N", "Longitude": 602957.46, "Latitude": 4606801.99, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "White and black", "Face_type": "Exposed", "Photo": "INOV04_3.jpg", "Raw_Spectr": "INOV04_3", "Processed_": "INOV04_3_CR", "Spectra_ab": "INOV04_3_abs_1", "Spectra__1": "INOV04_3_abs_2", "Spectra__2": "INOV04_3_abs_3", "Spectra__3": null, "Spectra__4": null, "Spectral_m": "White mica/illite mixed with orthoclase; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764415557280173, 41.606292061781438 ] } },
{ "type": "Feature", "properties": { "ID": 16.0, "Sample_nr": "INOV04", "Spectrum_n": "INOV04_4", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz- Iron Oxide", "WGS84_Zone": "29N", "Longitude": 602957.46, "Latitude": 4606801.99, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Black and yellowish", "Face_type": "Exposed", "Photo": "INOV04_4.jpg", "Raw_Spectr": "INOV04_4", "Processed_": "INOV04_4_CR", "Spectra_ab": "INOV04_4_abs_1", "Spectra__1": "INOV04_4_abs_2", "Spectra__2": "INOV04_4_abs_3", "Spectra__3": "INOV04_4_abs_4", "Spectra__4": null, "Spectral_m": "Montmorillonite mixed with illite and possibly cookeite; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764415557280173, 41.606292061781438 ] } },
{ "type": "Feature", "properties": { "ID": 17.0, "Sample_nr": "INOV04", "Spectrum_n": "INOV04_5", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602957.46, "Latitude": 4606801.99, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "White", "Face_type": "Exposed", "Photo": "INOV04_5.jpg", "Raw_Spectr": "INOV04_5", "Processed_": "INOV04_5_CR", "Spectra_ab": "INOV04_5_abs_1", "Spectra__1": "INOV04_5_abs_2", "Spectra__2": null, "Spectra__3": null, "Spectra__4": null, "Spectral_m": "White mica/illite mixed with orthoclase; iron features in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764415557280173, 41.606292061781438 ] } },
{ "type": "Feature", "properties": { "ID": 18.0, "Sample_nr": "INOV04", "Spectrum_n": "INOV04_6", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602957.46, "Latitude": 4606801.99, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Rose", "Face_type": "Exposed", "Photo": "INOV04_6.jpg", "Raw_Spectr": "INOV04_6", "Processed_": "INOV04_6_CR", "Spectra_ab": "INOV04_6_abs_1", "Spectra__1": "INOV04_6_abs_2", "Spectra__2": "INOV04_6_abs_3", "Spectra__3": "INOV04_6_abs_4", "Spectra__4": null, "Spectral_m": "White mica/sericite mixed with chlorite (possibly cookeite ?); iron features in VNIR and SWIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764415557280173, 41.606292061781438 ] } },
{ "type": "Feature", "properties": { "ID": 19.0, "Sample_nr": "INOV05", "Spectrum_n": "INOV05_1", "Locality": "Portugal-Barroso", "Sample_des": "Aplite-Pegmatite/ muscovite, plagioclase, quartz", "WGS84_Zone": "29N", "Longitude": 602968.25, "Latitude": 4606790.88, "Preparatio": "drying at 50ºC", "Analysis": "ASD FieldSpec 4", "Stored": "UPORTO", "Face_color": "Gray and white", "Face_type": "Exposed", "Photo": "INOV05_1.jpg", "Raw_Spectr": "INOV05_1", "Processed_": "INOV05_1_CR", "Spectra_ab": "INOV05_1_abs_1", "Spectra__1": "INOV05_1_abs_2", "Spectra__2": "INOV05_1_abs_3", "Spectra__3": null, "Spectra__4": null, "Spectral_m": "Illite; detected Fe3+ in VNIR" }, "geometry": { "type": "Point", "coordinates": [ -7.764288005570608, 41.606190622497969 ] } },....
And until now I tested and the problem is that for the first point (as example) that have 5 rows in attribute table, it only reads the fifth row information. How do I get the other rows (1 to 4)?
lyrSpectral = L.geoJSON.ajax('data/spectral_library.geojson', {pointToLayer:returnVector}).addTo(mymap);
lyrSpectral.on('data:loaded', function() {
mymap.fitBounds(lyrSpectral.getBounds());
});
function returnVector(json, latlng){
var att = json.properties;
var Tab1content = '<p>ID: ' + att.ID + '</p><p>Sample Number: '+ att.Sample_nr + '</p><p>Spectrum Number: '+ att.Spectrum_n +'</p><p>Face Color: '+ att.Face_color +'</p><p>Face Type: '+ att.Face_type +'</p><p>Sample_description: '+ att.Sample_des+'</p><p>Spectral_m: '+ att.Spectral_m + + att.Spectral_m;
var content = '<div class="tabs" style="width: 400px; height: 300px">' +
'<div class="tab" id="tab-1">' +
'<div class="content">' +
'<b>'+Tab1content +'</b>' +
'</div>' +
'</div>' +
'<div class="tab" id="tab-2">' +
'<div class="content">' +
'<b>Tab 2 content</b>' +
'</div>' +
'</div>' +
'<div class="tab" id="tab-3">' +
'<div class="content">' +
'<b>Tab 3 content</b>' +
'</div>' +
'</div>' +
'<ul class="tabs-link">' +
'<li class="tab-link"> <span>'+att.ID+'</span></li>' +
'<li class="tab-link"> <span>ID2</span></li>' +
'<li class="tab-link"> <span>ID3</span></li>' +
'</ul>' +
'</div>';
return L.circleMarker(latlng, {radius:5, color:'blue'}).bindPopup(
content,{
maxWidth: "auto"
});
}
The result seems like this:

Related

How to insert header tags to API Json

Hello im making a GET api in laravel that shows values from database and im trying to make it that the returned json result to have a header tag an example is this public api
https://dummy.restapiexample.com/api/v1/employees
As you can see this api shows the status:success and then data: , this is my code:
function getDevice()
{
return Client::all();
}
And this is the result i get in postman:
data [ //here to have a header
{
"id": 1,
"name": "Mr. Omari Schaefer DVM",
"email": "kulas.julian#example.net",
"phone_number": "0697830800",
"age": "29",
"salary": "150",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 2,
"name": "Hattie Brakus",
"email": "deckow.coby#example.com",
"phone_number": "0697830800",
"age": "30",
"salary": "565",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 3,
"name": "Sabrina Rosenbaum",
"email": "kautzer.madison#example.net",
"phone_number": "0697830800",
"age": "31",
"salary": "254",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 4,
"name": "Ms. Fiona Fritsch",
"email": "juwan.damore#example.net",
"phone_number": "0697830800",
"age": "32",
"salary": "029",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 5,
"name": "Michael Dooley",
"email": "hayes.reinhold#example.org",
"phone_number": "0697830800",
"age": "33",
"salary": "265",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 6,
"name": "Prof. Kelley Koepp Jr.",
"email": "kutch.jessie#example.org",
"phone_number": "0697830800",
"age": "34",
"salary": "688",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 7,
"name": "Herminia McClure PhD",
"email": "ywillms#example.com",
"phone_number": "0697830800",
"age": "35",
"salary": "103",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 8,
"name": "Morton Considine",
"email": "lesly.pfeffer#example.com",
"phone_number": "0697830800",
"age": "36",
"salary": "804",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 9,
"name": "Katlyn Muller",
"email": "peter93#example.net",
"phone_number": "0697830800",
"age": "37",
"salary": "695",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 10,
"name": "Wilber Stehr",
"email": "bmckenzie#example.net",
"phone_number": "0697830800",
"age": "38",
"salary": "941",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 11,
"name": "Test User",
"email": "test#example.com",
"phone_number": "0697830800",
"age": "60",
"salary": "448",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
}
]
What im trying to do is:
[
{
"id": 1,
"name": "Mr. Omari Schaefer DVM",
"email": "kulas.julian#example.net",
"phone_number": "0697830800",
"age": "29",
"salary": "150",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 2,
"name": "Hattie Brakus",
"email": "deckow.coby#example.com",
"phone_number": "0697830800",
"age": "30",
"salary": "565",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 3,
"name": "Sabrina Rosenbaum",
"email": "kautzer.madison#example.net",
"phone_number": "0697830800",
"age": "31",
"salary": "254",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 4,
"name": "Ms. Fiona Fritsch",
"email": "juwan.damore#example.net",
"phone_number": "0697830800",
"age": "32",
"salary": "029",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 5,
"name": "Michael Dooley",
"email": "hayes.reinhold#example.org",
"phone_number": "0697830800",
"age": "33",
"salary": "265",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 6,
"name": "Prof. Kelley Koepp Jr.",
"email": "kutch.jessie#example.org",
"phone_number": "0697830800",
"age": "34",
"salary": "688",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 7,
"name": "Herminia McClure PhD",
"email": "ywillms#example.com",
"phone_number": "0697830800",
"age": "35",
"salary": "103",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 8,
"name": "Morton Considine",
"email": "lesly.pfeffer#example.com",
"phone_number": "0697830800",
"age": "36",
"salary": "804",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 9,
"name": "Katlyn Muller",
"email": "peter93#example.net",
"phone_number": "0697830800",
"age": "37",
"salary": "695",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 10,
"name": "Wilber Stehr",
"email": "bmckenzie#example.net",
"phone_number": "0697830800",
"age": "38",
"salary": "941",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
},
{
"id": 11,
"name": "Test User",
"email": "test#example.com",
"phone_number": "0697830800",
"age": "60",
"salary": "448",
"created_at": "2023-02-17T08:36:00.000000Z",
"updated_at": "2023-02-17T08:36:00.000000Z"
}
]
function getDevice()
{
return ['data' =>
Client::all(),
};
Please refer to the below solution for every response :
return response()->json('status' => 'success','message' => 'Client listing successfully.','data' => Client::all());
If you know how to use the helper function in Laravel then Please used the below for all responses:
Example :
In Controller, Just add the below line :
return apiResponse('success','Client listed successfully',Client::all()]);
if (!function_exists('apiResponse')) {
function apiResponse($status = null, $message = null, $data = null, $code = 200, $extra = []) {
$response = [
'status' => $status,
'message' => $message,
'data' => $data,
];
if(!empty($extra)){
$response = array_merge($response,$extra);
}
return response()->json($response, $code);
}
}
I think this will help you a lot.

How to get one element from array of objects in elasticsearch

I have a products index which has an offers field. Offers is an array of objects.
I want to return one offer by seller_id in an array or in a new field.
Input:
with seller_id=5
{
"_index":"dev_products",
"_type":"_doc",
"_id":"138",
"_score":1.0,
"_source":{
"is_adult":false,
"status_id":3,
"allow_publish":false,
"name":"Consequuntur expedita sit perferendis est.",
"category_id":816,
"brand_id":363,
"description":"Nec.",
"type":3,
"vendor_code":"4968258909901",
"barcode":"98735976",
"code":"consequuntur-expedita-sit-perferendis-est",
"updated_at":"2022-11-15T10:42:33.000000Z",
"created_at":"2022-11-15T10:42:33.000000Z",
"id":138,
"offers":[
{
"product_id":"138",
"seller_id":"1",
"sale_status":"2",
"external_id":"1267631",
"store_id":"2",
"qty":"44",
"storage_address":"",
"base_price":"312.84",
"updated_at":"2022-11-15T10:42:49.000000Z",
"created_at":"2022-11-15T10:42:49.000000Z",
"id":74
},
{
"product_id":"138",
"seller_id":"2",
"sale_status":"1",
"external_id":"2795841",
"store_id":"2",
"qty":"1",
"storage_address":"",
"base_price":"1812.3",
"updated_at":"2022-11-15T10:44:50.000000Z",
"created_at":"2022-11-15T10:44:50.000000Z",
"id":76
},
{
"product_id":"138",
"seller_id":"3",
"sale_status":"1",
"external_id":"32219",
"store_id":"1",
"qty":"32",
"storage_address":"",
"base_price":"1556.25",
"updated_at":"2022-11-15T10:50:16.000000Z",
"created_at":"2022-11-15T10:50:16.000000Z",
"id":77
},
{
"product_id":"138",
"seller_id":"4",
"sale_status":"1",
"external_id":"967427",
"store_id":"1",
"qty":"35",
"storage_address":"",
"base_price":"137.62",
"updated_at":"2022-11-15T10:50:18.000000Z",
"created_at":"2022-11-15T10:50:18.000000Z",
"id":78
},
{
"product_id":"138",
"seller_id":"5",
"sale_status":"2",
"external_id":"209466",
"store_id":"1",
"qty":"45",
"storage_address":"",
"base_price":"187.03",
"updated_at":"2022-11-15T10:50:19.000000Z",
"created_at":"2022-11-15T10:50:19.000000Z",
"id":79
},
{
"product_id":"138",
"seller_id":"6",
"sale_status":"1",
"external_id":"522912",
"store_id":"1",
"qty":"61",
"storage_address":"",
"base_price":"306.39",
"updated_at":"2022-11-15T10:50:20.000000Z",
"created_at":"2022-11-15T10:50:20.000000Z",
"id":80
}
]
}
}
Expected:
{
"_index":"dev_products",
"_type":"_doc",
"_id":"138",
"_score":1.0,
"_source":{
"is_adult":false,
"status_id":3,
"allow_publish":false,
"name":"Consequuntur expedita sit perferendis est.",
"category_id":816,
"brand_id":363,
"description":"Nec.",
"type":3,
"vendor_code":"4968258909901",
"barcode":"98735976",
"code":"consequuntur-expedita-sit-perferendis-est",
"updated_at":"2022-11-15T10:42:33.000000Z",
"created_at":"2022-11-15T10:42:33.000000Z",
"id":138,
"offers":[
{
"product_id":"138",
"seller_id":"5",
"sale_status":"2",
"external_id":"209466",
"store_id":"1",
"qty":"45",
"storage_address":"",
"base_price":"187.03",
"updated_at":"2022-11-15T10:50:19.000000Z",
"created_at":"2022-11-15T10:50:19.000000Z",
"id":79
}
]
}
}
Or expected:
{
"_index":"dev_products",
"_type":"_doc",
"_id":"138",
"_score":1.0,
"_source":{
"is_adult":false,
"status_id":3,
"allow_publish":false,
"name":"Consequuntur expedita sit perferendis est.",
"category_id":816,
"brand_id":363,
"description":"Nec.",
"type":3,
"vendor_code":"4968258909901",
"barcode":"98735976",
"code":"consequuntur-expedita-sit-perferendis-est",
"updated_at":"2022-11-15T10:42:33.000000Z",
"created_at":"2022-11-15T10:42:33.000000Z",
"id":138,
"offer":{
"product_id":"138",
"seller_id":"5",
"sale_status":"2",
"external_id":"209466",
"store_id":"1",
"qty":"45",
"storage_address":"",
"base_price":"187.03",
"updated_at":"2022-11-15T10:50:19.000000Z",
"created_at":"2022-11-15T10:50:19.000000Z",
"id":79
}
}
}
Thanks for help!
If the offers field is nested type you can to use inner hits to get only object match in list.
The object you expected will in "inner_hits" response.
Query
GET idx_nested/_search?filter_path=hits.hits
{
"query": {
"nested": {
"path": "offers",
"query": {
"match": {
"offers.seller_id": "5"
}
},
"inner_hits": {}
}
}
}
Response:
{
"hits": {
"hits": [
{
"_index": "idx_nested",
"_id": "kYyYf4QBgXg8h_rctd1z",
"_score": 1.540445,
"_source": {
"is_adult": false,
"status_id": 3,
"allow_publish": false,
"name": "Consequuntur expedita sit perferendis est.",
"category_id": 816,
"brand_id": 363,
"description": "Nec.",
"type": 3,
"vendor_code": "4968258909901",
"barcode": "98735976",
"code": "consequuntur-expedita-sit-perferendis-est",
"updated_at": "2022-11-15T10:42:33.000000Z",
"created_at": "2022-11-15T10:42:33.000000Z",
"id": 138,
"offers": [
{
"product_id": "138",
"seller_id": "1",
"sale_status": "2",
"external_id": "1267631",
"store_id": "2",
"qty": "44",
"storage_address": "",
"base_price": "312.84",
"updated_at": "2022-11-15T10:42:49.000000Z",
"created_at": "2022-11-15T10:42:49.000000Z",
"id": 74
},
{
"product_id": "138",
"seller_id": "2",
"sale_status": "1",
"external_id": "2795841",
"store_id": "2",
"qty": "1",
"storage_address": "",
"base_price": "1812.3",
"updated_at": "2022-11-15T10:44:50.000000Z",
"created_at": "2022-11-15T10:44:50.000000Z",
"id": 76
},
{
"product_id": "138",
"seller_id": "3",
"sale_status": "1",
"external_id": "32219",
"store_id": "1",
"qty": "32",
"storage_address": "",
"base_price": "1556.25",
"updated_at": "2022-11-15T10:50:16.000000Z",
"created_at": "2022-11-15T10:50:16.000000Z",
"id": 77
},
{
"product_id": "138",
"seller_id": "4",
"sale_status": "1",
"external_id": "967427",
"store_id": "1",
"qty": "35",
"storage_address": "",
"base_price": "137.62",
"updated_at": "2022-11-15T10:50:18.000000Z",
"created_at": "2022-11-15T10:50:18.000000Z",
"id": 78
},
{
"product_id": "138",
"seller_id": "5",
"sale_status": "2",
"external_id": "209466",
"store_id": "1",
"qty": "45",
"storage_address": "",
"base_price": "187.03",
"updated_at": "2022-11-15T10:50:19.000000Z",
"created_at": "2022-11-15T10:50:19.000000Z",
"id": 79
},
{
"product_id": "138",
"seller_id": "6",
"sale_status": "1",
"external_id": "522912",
"store_id": "1",
"qty": "61",
"storage_address": "",
"base_price": "306.39",
"updated_at": "2022-11-15T10:50:20.000000Z",
"created_at": "2022-11-15T10:50:20.000000Z",
"id": 80
}
]
},
"inner_hits": {
"offers": {
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.540445,
"hits": [
{
"_index": "idx_nested",
"_id": "kYyYf4QBgXg8h_rctd1z",
"_nested": {
"field": "offers",
"offset": 4
},
"_score": 1.540445,
"_source": {
"store_id": "1",
"updated_at": "2022-11-15T10:50:19.000000Z",
"storage_address": "",
"product_id": "138",
"qty": "45",
"base_price": "187.03",
"sale_status": "2",
"created_at": "2022-11-15T10:50:19.000000Z",
"external_id": "209466",
"id": 79,
"seller_id": "5"
}
}
]
}
}
}
}
]
}
}

Elasticsearch document sorting based on nested values

I have the following data indexed in my elasticsearch version 7.4.
[
{
"users": [
{
"age": "31",
"dept": "IT",
"city": "Chennai"
},
{
"age": "25",
"dept": "Accounts",
"city": "Bengaluru"
},
{
"age": "26",
"dept": "Finance",
"city": "Kochi"
}
],
"isActive": true
},
{
"users": [
{
"age": "23",
"dept": "IT",
"city": "Chennai"
},
{
"age": "22",
"dept": "Finance",
"city": "Kochi"
},
{
"age": "21",
"dept": "Accounts",
"city": "Bengaluru"
}
],
"isActive": true
},
{
"users": [
{
"age": "28",
"dept": "IT",
"city": "Chennai"
},
{
"age": "22",
"dept": "Finance",
"city": "Kochi"
},
{
"age": "21",
"dept": "Accounts",
"city": "Bengaluru"
}
],
"isActive": true
},
{
"users": [
{
"age": "31",
"dept": "IT",
"city": "Kochi"
},
{
"age": "25",
"dept": "Finance",
"city": "Bengaluru"
},
{
"age": "26",
"dept": "Accounts",
"city": "Chennai"
}
],
"isActive": true
},
{
"users": [
{
"age": "21",
"dept": "IT",
"city": "Kochi"
},
{
"age": "45",
"dept": "Accounts",
"city": "Bengaluru"
},
{
"age": "26",
"dept": "Finance",
"city": "Chennai"
}
],
"isActive": false
}
]
the users is nested type
I want to sort the documents based on the following condition
isActive == true && users.dept == "IT" && users.city == "Chennai" with the age sorts in ascending
I am expecting the following result
[
{
"users": [
{
"age": "23",
"dept": "IT",
"city": "Chennai"
},
{
"age": "22",
"dept": "Finance",
"city": "Kochi"
},
{
"age": "21",
"dept": "Accounts",
"city": "Bengaluru"
}
],
"isActive": true
},
{
"users": [
{
"age": "28",
"dept": "IT",
"city": "Chennai"
},
{
"age": "22",
"dept": "Finance",
"city": "Kochi"
},
{
"age": "21",
"dept": "Accounts",
"city": "Bengaluru"
}
],
"isActive": true
},
{
"users": [
{
"age": "31",
"dept": "IT",
"city": "Chennai"
},
{
"age": "25",
"dept": "Accounts",
"city": "Bengaluru"
},
{
"age": "26",
"dept": "Finance",
"city": "Kochi"
}
],
"isActive": true
},
{
"users": [
{
"age": "31",
"dept": "IT",
"city": "Kochi"
},
{
"age": "25",
"dept": "Finance",
"city": "Bengaluru"
},
{
"age": "26",
"dept": "Accounts",
"city": "Chennai"
}
],
"isActive": true
}
]
I tried with script based sorting, I couldn't able to achieve the result.
Please help me to sort this out.
Thanks in advance.

jqgrid treeGrid Cannot read property 'rowIndex' of undefined

I try to use local data with treeGrid, when i click the unfold
button . I get the tips "Cannot read property 'rowIndex' of
undefined"
<!DOCTYPE html>
<html lang="en">
<head>
<!-- The jQuery library is a prerequisite for all jqSuite products -->
<script type="text/ecmascript" src="./js/jquery.min.js"></script>
<!-- This is the Javascript file of jqGrid -->
<script type="text/ecmascript" src="./js/jquery.jqGrid.min.js"></script>
<!-- This is the localization file of the grid controlling messages, labels, etc.
<!-- We support more than 40 localizations -->
<script type="text/ecmascript" src="./js/i18n/grid.locale-en.js"></script>
<!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom -->
<link rel="stylesheet" type="text/css" media="screen" href="./css/jquery-ui-1.10.4.custom.min.css" />
<!-- The link to the CSS that the grid needs -->
<link rel="stylesheet" type="text/css" media="screen" href="./css/ui.jqgrid.css" />
<meta charset="utf-8" />
<title>jqTreeGrid - Load On Demand - Load all Rows at once collapsed</title>
</head>
<body>
<table id="tree"></table>
<div id="pager"></div>
<script type="text/javascript">
var rows = [
{
"category_id": "1",
"name": "ELECTRONICS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "1",
"rgt": "44",
"level": "0",
"uiicon": ""
},
{
"category_id": "2",
"name": "TELEVISIONS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "2",
"rgt": "19",
"level": "1",
"uiicon": ""
},
{
"category_id": "3",
"name": "TUBE",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "3",
"rgt": "8",
"level": "2",
"uiicon": ""
},
{
"category_id": "11",
"name": "26 \" TV",
"price": "200.00",
"qty_onhand": "1",
"color": "black",
"lft": "4",
"rgt": "5",
"level": "3",
"uiicon": "ui-icon-image"
},
{
"category_id": "12",
"name": "30 \" TV",
"price": "350.00",
"qty_onhand": "2",
"color": "black",
"lft": "6",
"rgt": "7",
"level": "3",
"uiicon": "ui-icon-document"
},
{
"category_id": "4",
"name": "LCD",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "9",
"rgt": "12",
"level": "2",
"uiicon": ""
},
{
"category_id": "13",
"name": "Super-LCD 42\" ",
"price": "400.00",
"qty_onhand": "10",
"color": "all",
"lft": "10",
"rgt": "11",
"level": "3",
"uiicon": "ui-icon-video"
},
{
"category_id": "5",
"name": "PLASMA",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "13",
"rgt": "18",
"level": "2",
"uiicon": ""
},
{
"category_id": "14",
"name": "Ultra-Plasma 62\" ",
"price": "440.00",
"qty_onhand": "2",
"color": "silver",
"lft": "14",
"rgt": "15",
"level": "3",
"uiicon": "ui-icon-clipboard"
},
{
"category_id": "15",
"name": "Value Plasma 38\" ",
"price": "312.00",
"qty_onhand": "0",
"color": "silver",
"lft": "16",
"rgt": "17",
"level": "3",
"uiicon": "ui-icon-clipboard"
},
{
"category_id": "6",
"name": "PORTABLE ELECTRONICS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "20",
"rgt": "43",
"level": "1",
"uiicon": ""
},
{
"category_id": "7",
"name": "MP3 PLAYERS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "21",
"rgt": "32",
"level": "2",
"uiicon": ""
},
{
"category_id": "8",
"name": "FLASH",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "22",
"rgt": "29",
"level": "3",
"uiicon": ""
},
{
"category_id": "17",
"name": "Super-Shuffle 1gb",
"price": "20.00",
"qty_onhand": "11",
"color": "all",
"lft": "23",
"rgt": "24",
"level": "4",
"uiicon": "ui-icon-note"
},
{
"category_id": "21",
"name": "5Gb Flash",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "25",
"rgt": "26",
"level": "4",
"uiicon": "ui-icon-comment"
},
{
"category_id": "22",
"name": "10Gb flash ",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "27",
"rgt": "28",
"level": "4",
"uiicon": "ui-icon-tag"
},
{
"category_id": "16",
"name": " Power-MP3 128mb",
"price": "123.00",
"qty_onhand": "2",
"color": "withe",
"lft": "30",
"rgt": "31",
"level": "3",
"uiicon": "ui-icon-signal-diag"
},
{
"category_id": "9",
"name": "CD PLAYERS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "33",
"rgt": "38",
"level": "2",
"uiicon": ""
},
{
"category_id": "18",
"name": " Porta CD ",
"price": "10.00",
"qty_onhand": "0",
"color": "",
"lft": "34",
"rgt": "35",
"level": "3",
"uiicon": "ui-icon-eject"
},
{
"category_id": "19",
"name": "CD To go!",
"price": "110.00",
"qty_onhand": "11",
"color": "",
"lft": "36",
"rgt": "37",
"level": "3",
"uiicon": "ui-icon-power"
},
{
"category_id": "10",
"name": "2 WAY RADIOS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "39",
"rgt": "42",
"level": "2",
"uiicon": ""
},
{
"category_id": "20",
"name": "Family Talk 360 ",
"price": "200.00",
"qty_onhand": "15",
"color": "",
"lft": "40",
"rgt": "41",
"level": "3",
"uiicon": "ui-icon-volume-on"
},
{
"category_id": "23",
"name": "COMPUTERS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "45",
"rgt": "50",
"level": "0",
"uiicon": ""
},
{
"category_id": "25",
"name": "DESKTOP ",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "46",
"rgt": "47",
"level": "1",
"uiicon": ""
},
{
"category_id": "26",
"name": "LAPTOPS",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "48",
"rgt": "49",
"level": "1",
"uiicon": ""
},
{
"category_id": "24",
"name": "APPLIANCES",
"price": "0.00",
"qty_onhand": "0",
"color": "",
"lft": "51",
"rgt": "52",
"level": "0",
"uiicon": ""
}
]
jQuery(document).ready(function ($) {
jQuery('#tree').jqGrid({
// "url":"data.json",
"colModel": [
{
"name": "category_id",
"index": "accounts.account_id",
"sorttype": "int",
"key": true,
"hidden": true,
"width": 50
}, {
"name": "name",
"index": "name",
"sorttype": "string",
"label": "Name",
"width": 170
}, {
"name": "price",
"index": "price",
"sorttype": "numeric",
"label": "Price",
"width": 90,
"align": "right"
}, {
"name": "qty_onhand",
"index": "qty_onhand",
"sorttype": "int",
"label": "Qty",
"width": 90,
"align": "right"
}, {
"name": "color",
"index": "color",
"sorttype": "string",
"label": "Color",
"width": 100
}, {
"name": "lft",
"hidden": true
}, {
"name": "rgt",
"hidden": true
}, {
"name": "level",
"hidden": true
}, {
"name": "uiicon",
"hidden": true
}
],
"width": "780",
"hoverrows": false,
"viewrecords": false,
"gridview": true,
"height": "auto",
"sortname": "lft",
"loadonce": true,
"rowNum": 100,
"scrollrows": true,
// enable tree grid
"treeGrid": true,
// which column is expandable
"ExpandColumn": "name",
// datatype
"treedatatype": "json",
// the model used
"treeGridModel": "nested",
// configuration of the data comming from server
"treeReader": {
"left_field": "lft",
"right_field": "rgt",
"level_field": "level",
"leaf_field": "isLeaf",
"expanded_field": "expanded",
"loaded": "loaded",
"icon_field": "icon"
},
// "sortorder": "asc",
"datatype": "local",
"data": rows,
"pager": "#pager"
});
});
</script>
</body>
</html>
For localdata type, you must configure the localReader parameter:
localReader: {
repeatitems: true,
// cell: "",
id: "category_id"
}

Kendo ui grid server-side pagination not working?

I'm trying to implement server-side pagination with kendo-ui grid. This is my datasource configuration.
"dataSource": {
"serverPaging": true,
"pageSize": 10,
"schema":{
"data": "data",
"total": "total"
},
"transport": {
"read": {
"url": "http://localhost:9001/category/widget/kendoGridTest/trigger/data",
"dataType": "json",
"type": "GET"
}
}
}
When I run it, it continuously sending server requests but nothing happening. The sending requests are correct and getting the expected response too. No data-binding on the grid happening.
Anyone has idea what has gone wrong here??
Edit: Server Response
{
"data": [
{
"CustomerID": "ALFKI",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"Address": "Obere Str. 57",
"City": "Berlin"
},
{
"CustomerID": "YUI",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"Address": "Obere Str. 57",
"City": "Berlin"
},
{
"CustomerID": "PKY",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"Address": "Obere Str. 57",
"City": "Berlin"
},
{
"CustomerID": "PNY",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"Address": "Obere Str. 57",
"City": "Berlin"
},
{
"CustomerID": "WSI",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"Address": "Obere Str. 57",
"City": "Berlin"
},
{
"CustomerID": "FGH",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"Address": "Obere Str. 57",
"City": "Berlin"
},
{
"CustomerID": "NMV",
"CompanyName": "Alfreds Futterkiste",
"ContactName": "Maria Anders",
"ContactTitle": "Sales Representative",
"Address": "Obere Str. 57",
"City": "Berlin"
}
],
"total": 7
}

Resources