jQWidgets Forums

jQuery UI Widgets Forums Grid Populating checkedlist using JSON

This topic contains 2 replies, has 2 voices, and was last updated by  RedantJ 9 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Populating checkedlist using JSON #80640

    RedantJ
    Participant

    Hey, once again:

    In my controller program, I’ve created a JSON which looks likes this:

    [
    	{
    	"TotalRows": 3
    	},
    	{
    	"Rows": [
    		{
    			"ID":"1",
    			"foo1":"Mary",
    			"foo2":"Ford",
    			"foo3":"100"
    		},
    		{
    			"ID":"2",
    			"foo1":"Sean",
    			"foo2":"Saab",
    			"foo3":"80"
    		},
    		{
    			"ID":"3",
    			"foo1":"Ivan",
    			"foo2":"Fiat",
    			"foo3":"90"
    		}
    		]
    	},
    	{
    	"TransportationList": [
    			"Ford",
    			"Fiat",
    			"Saab",
    			"Bus",
    			"Bicycle",
    			"None"
    		]
    	},
    	{
    	"EmployeeList": [
    			"Mary",
    			"Ivan",
    			"Sean",
    			"Geoff",
    			"Liam",
    			"Stan"
    		]
    	}
    ]

    This JSON changes when a filter is applied. For example, if the user selects “Saab”, then the JSON becomes:

    [
    	{
    	"TotalRows": 1
    	},
    	{
    	"Rows": [
    		{
    			"ID":"2",
    			"foo1":"Sean",
    			"foo2":"Saab",
    			"foo3":"80"
    		}
    		]
    	},
    	{
    	"TransportationList": [
    			"Saab"
    		]
    	},
    	{
    	"EmployeeList": [
    			"Sean"
    		]
    	}
    ]

    I am able to populate the grid, and I am able to populate the “checkedlist” in the Filter row on intialisation:

    	var TransportationList = new Array();
    	
    	var EmployeeList = new Array();	
          
    	var source =
    	{
    		datatype: "json",
    		datafields: [
    			{ name: 'ID', type: 'string'},
    			{ name: 'foo1', type: 'string' },
    			{ name: 'foo2', type: 'string' },
    			{ name: 'foo3', type: 'string' }
    		],
    		cache: false,
    		url: 'server.asp',
    		filter: function()
    		{
    			$("#jqxgrid").jqxGrid('updatebounddata', 'filter');
    		},
    		sort: function()
    		{
    			$("#jqxgrid").jqxGrid('updatebounddata', 'sort');
    		},
    		root: 'Rows',
    		beforeprocessing: function(data)
    		{		
    			if (data != null)
    			{
    				source.totalrecords = data[0].TotalRows;
    
    				for (var i = 0; i < data[2].TransportationList.length; i++)
    				{
    					TransportationList.push(data[2].TransportationList[i]);
    				}
    				for (var i = 0; i < data[3].EmployeeList.length; i++)
    				{
    					EmployeeList.push(data[3].EmployeeList[i]);
    				}
    				
    			}
    		}
    	};
    

    This sounds like an easy problem: How can I reload the “checklist” in the Filter Row after a new filter is applied?

    Populating checkedlist using JSON #80690

    Hristo
    Participant

    Hello RedantJ,

    The described case is not possible if I understand correct.
    You could use filteritems: to set a particular list of items.
    We have such demo: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/filterrowwithcustomitems.htm?arctic

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

    Populating checkedlist using JSON #80707

    RedantJ
    Participant

    That is how I’m calling it, yes:

    	columns: [
    		{ text: 'Foo 1', datafield: 'foo1', filtertype: 'checkedlist', filteritems: EmployeeList, width: 130 },				
    		{ text: 'Foo 2', datafield: 'foo2', filtertype: 'checkedlist', filteritems: TransportationList, width: 130 },
    		{ text: 'Foo 3', datafield: 'foo3', filtertype: 'input', width: 130 }
    		]				
    

    If it’s not possible, then it’s not possible. Thanks anyway, Hristo!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.