jQWidgets Forums

jQuery UI Widgets Forums Grid foreign collection of values for a datafield in grid not work!

This topic contains 3 replies, has 2 voices, and was last updated by  Martin 6 years, 5 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author

  • fabiocerri
    Participant

    Hi to all,
    I try to connect two grids with foreign collection of values for a datafield parameter in dataadapter. It doesn’t work.
    This is the code:

    
    $(document).ready(function () {
    
    	var gblMainFiles = [
    		{myid:1, directory:'dirA1', filename:'example-file-A1.mp3'},
    		{myid:2, directory:'dirA2', filename:'example-file-A2.mp3'},
    		{myid:3, directory:'dirA3', filename:'example-file-A3.mp3'},
    		{myid:4, directory:'dirA4', filename:'example-file-A4.mp3'},
    		{myid:5, directory:'dirA5', filename:'example-file-A5.mp3'},
    		{myid:6, directory:'dirA6', filename:'example-file-A6.mp3'},
    		{myid:7, directory:'dirA7', filename:'example-file-A7.mp3'},
    		{myid:8, directory:'dirA8', filename:'example-file-A8.mp3'},
    	];
    
    	// =======================================================
    	// SOURCES
    	// =======================================================
    
    	var souMainFiles =
    	{
    		datatype: "array",
    		localdata: gblMainFiles,
    		datafields: [
    			{ name: 'myid'},
    			{ name: 'directory' },
    			{ name: 'filename'}
    		]
    	};
    	var daaMainFiles = new $.jqx.dataAdapter(souMainFiles, {autoBind:true});
    
    	var souPlayFiles =
    	{
    		datatype: "array",
    		localdata: [],
    		datafields: [
    			{ name: 'myid2Play'},
    			{ name: 'directory', value: 'myid2Play', values: {source: daaMainFiles.records, value: 'myid', name: 'directory'}},
    			{ name: 'filename', value: 'myid2Play', values: {source: daaMainFiles.records, value: 'myid', name: 'filename'}},
    		]
    	};
    	var daaPlayFiles = new $.jqx.dataAdapter(souPlayFiles, {autoBind:true});
    
    	// =======================================================
    	// GRIDS
    	// =======================================================
    
    	$("#grd-mainfiles").jqxGrid(
    	{
    		source: daaMainFiles,
    		columns: [
    			{ text: 'id', datafield: 'myid'},
    			{ text: 'dir', datafield: 'directory'},
    			{ text: 'file', datafield: 'filename'}
    		],
    	});
    
    	$("#grd-playfiles").jqxGrid(
    	{
    		source: daaPlayFiles,
    		columns: [
    			{ text: 'id', datafield: 'myid2Play'},
    			{ text: 'dir', datafield: 'directory'},
    			{ text: 'file', datafield: 'filename'}
    		],
    	});
    
    	// =======================================================
    	// BUTTON
    	// =======================================================
    
    	$("#btn1").jqxButton();	
    	$("#btn2").jqxButton();	
    	
    	$("#btn1").on('click', function () {
    		var playlist = new Array();
    		playlist.push({'myid2Play': 2});
    		playlist.push({'myid2Play': 1});
    		playlist.push({'myid2Play': 4});
    		
    		souPlayFiles.localdata = playlist;
    		$("#grd-playfiles").jqxGrid('updatebounddata');
    
    	});
    
    	
    	$("#btn2").on('click', function () {
    		var mf = new Array();
    		var mf = [
    			{myid:1, directory:'dirB1', filename:'example-file-B1.mp3'},
    			{myid:2, directory:'dirB2', filename:'example-file-B2.mp3'},
    			{myid:3, directory:'dirB3', filename:'example-file-B3.mp3'},
    			{myid:4, directory:'dirB4', filename:'example-file-B4.mp3'},
    			{myid:6, directory:'dirB6', filename:'example-file-B6.mp3'},
    			{myid:7, directory:'dirB7', filename:'example-file-B7.mp3'},
    		];
    		souMainFiles.localdata = mf;
    		$("#grd-mainfiles").jqxGrid('updatebounddata');
    
    	});
    });
    

    if I click btn1, grd-playfiles get right data from grd-mainfiles.
    But if I repeat click btn1 after click btn2 (that change grd-mainfiles data), nothing happens. A possible solution?
    Thanks, Fabio


    Martin
    Participant

    Hello Fabio,

    When you are updating the “playfiles” grid by clicking btn2,
    you also need to update souPlayFiles datafields’ values’ sources, as daaMainFiles.records might have changed.

    I have created an Example, using your code.

    Best Regards,
    Martin

    jQWidgets Team
    http://www.jqwidgets.com/


    fabiocerri
    Participant

    Thanks Martin, now I understand, I will use your suggestion!
    I thought the datafields were updated automatically. Is there an automatic way without rewriting the datafields source each time?
    Thanks,
    Fabio


    Martin
    Participant

    Hello Fabio,

    I am glad I was able to help you!
    They are not updated automatically. You should do it, as shown in the example above.

    Best Regards,
    Martin

    jQWidgets Team
    http://www.jqwidgets.com/

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

You must be logged in to reply to this topic.