Page 1 of 1

json to grid

Posted: Sat Mar 27, 2021 5:17 pm
by gregc

I see you have a grid defined as html and parsed out, like Dojo.

Does it make sense to have a grid defined as JSON that could do something like
grid = new Grid(json);

I guess its the advanced functionality with functions and the like where you would run into limitations but I could see how it could be more convenient for the server to generate json for simple tables.


Re: json to grid

Posted: Sat Mar 27, 2021 5:56 pm
by mats

Sure, you can generate a grid however you want. Simple scenarios can for sure be described as pure JSON as you discovered.


Re: json to grid

Posted: Fri Oct 22, 2021 2:46 pm
by Animal

I'm not sure where you are getting your impressions from.

new Grid({ object notation }) is exactly how it works.

You pass an object.

JSON is a string encoding of an object. So if you have JSON, you need to use JSON.parse to turn it into an object, then pass it to the Grid constructor. It's that simple.


Re: json to grid

Posted: Fri Oct 22, 2021 6:03 pm
by gregc

What was confusing was when I create the grid I have code like

cellMenu : { 
items : { 
	  removeRow : false 
		,updateWeights : { text: 'Update elo', weight: 0, onItem : rightclickitem, urlParams : '', actionRefId: 476} 
		,resetElo : { text: 'Reset elo', weight: 5, onItem : rightclickitem, urlParams : '', actionRefId: 477} 
		,reviewItem : { text: 'Mark Reviewed', weight: 15, onItem : rightclickitem, urlParams : 'Status=9805', actionRefId: 370} 
		,testedItem : { text: 'Mark Tested', weight: 20, onItem : rightclickitem, urlParams : 'Status=9806', actionRefId: 370} 
		,futureItem : { text: 'Mark Future', weight: 25, onItem : rightclickitem, urlParams : 'Status=9807', actionRefId: 370} 
		,naItem : { text: 'Mark N/A', weight: 28, onItem : rightclickitem, urlParams : 'Status=10454', actionRefId: 370} 
		,resetItem : { text: 'Reset verify status', weight: 30, onItem : rightclickitem, urlParams : 'Status=0', actionRefId: 370} 
		,championItem : { text: 'Make champion', weight: 30, onItem : rightclickitem, urlParams : 'championInd=1', actionRefId: 456} 
		,championRemoveItem : { text: 'Remove champion', weight: 30, onItem : rightclickitem, urlParams : 'championInd=0', actionRefId: 456} 
		,changeItemItem : { text: 'Change image', weight: 40, onItem : rightclickitem, urlParams : '', actionRefId: 396} 
, editItem : { text: 'Edit Character Sheet', weight: 45, onItem : rightclickitem,  actionRefId: 242} 
		, copyItem : { text: 'Copy Creature', weight: 60, onItem : rightclickurl,  actionRefId: 28},  
updateItem : { text: 'Update from DnDBeyond PDF', weight: 70, onItem : rightclickurl, actionRefId: 88}, updateFoundryItem : { text: 'Update from Foundry', weight: 80, onItem : rightclickurl, actionRefId: 417}, removeItem : { text: 'Inactivate', weight: 140, onItem : rightclickitem, confirmMsg : 'Press ok to remove SELECTIONCOUNT selected creatures', actionRefId:246 } }, processItems({ items, record, column }) { for (var key in items) { var item = items[key]; if (item.text && item.text.includes("quals")) { item.hidden = true; } if (window.genericgrid && window.genericgrid.selectedRecords && window.genericgrid.selectedRecords.length > 1) { if (item.text && item.text.includes("Copy")) { item.hidden = true; } if (item.text && item.text.includes("Edit")) { item.hidden = true; } } } }, } },

which does not look like JSON. So I'm not sure how it would be written in JSON.


Re: json to grid

Posted: Sun Oct 24, 2021 6:03 pm
by saki

Right, the above is not a proper json which requires double quotes around each name and value.

Tell us please what problem are you solving so that we can be more specific in our answers and can advise a concrete solution to your problem.

Meanwhile, take a look at the code of grid examples at https://localhost/bryntum-suite/Grid/examples/ - that can explain a lot.


Re: json to grid

Posted: Mon Oct 25, 2021 1:04 pm
by gregc

Its not something I would tackle any time in the next year I think, when I originally asked it was because I could have written better server side java code by creating a single java class that was the grid and then send it as json to the front end to be created. But I couldn't understand how the dynamic javascript code in processtimes could be represented as json.

processItems({ items, record, column }) { 
			for (var key in items) { 
					var item = items[key]; 
					if (item.text && item.text.includes("quals")) { 
                    	item.hidden = true; 
					} 
  if (window.genericgrid && window.genericgrid.selectedRecords && window.genericgrid.selectedRecords.length > 1) {
						if (item.text && item.text.includes("Copy")) { 
                     	item.hidden = true; 
						} 
						if (item.text && item.text.includes("Edit")) { 
                     	item.hidden = true; 
						} 
    }
					} 
 	 },		} 
    }, 

Not too important right now, just my confusion with javascript and json.


Re: json to grid

Posted: Mon Oct 25, 2021 1:11 pm
by mats

Right, JS functions are not part of the JSON specification (it's a data protocol) so you would need to handle that some other way.

https://stackoverflow.com/questions/2001449/is-it-valid-to-define-functions-in-json-results