Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82123

Adding edit/remove/create row function into table which contains array of objects

$
0
0
I have a problem with including functions that editing , removig and creating rows. The code stops working when I declarate an 'editor' as an dynamic array.. ;/ Here's the code. Maybe someone will help :)


 
                                <script type="text/javascript" language="javascript" src="js/jquery.js"></script>
		<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
		<script language="javascript" type="text/javascript" src="js/dataTables.editor.js"></script>
<script type="text/javascript" charset="utf-8">
			
			var editor;
			/* Data set - can contain whatever information you want */
			var aDataSet = [
				['Trident','Internet Explorer 4.0','Win 95+',Math.floor((Math.random()*10)+1),'X'],
				['Trident','Internet Explorer 5.0','Win 95+',Math.floor((Math.random()*10)+1),'C'],
				['Trident','Internet Explorer 5.5','Win 95+','5.5','A'],
				['Trident','Internet Explorer 6','Win 98+','6','A'],
				['Trident','Internet Explorer 7','Win XP SP2+','7','A'],
				['Trident','AOL browser (AOL desktop)','Win XP','6','A'],
				['Gecko','Firefox 1.0','Win 98+ / OSX.2+','1.7','A'],
				['Gecko','Firefox 1.5','Win 98+ / OSX.2+','1.8','A'],
				['Gecko','Firefox 2.0','Win 98+ / OSX.2+','1.8','A'],
				['Gecko','Firefox 3.0','Win 2k+ / OSX.3+','1.9','A'],
				['Gecko','Camino 1.0','OSX.2+','1.8','A'],
				['Gecko','Camino 1.5','OSX.3+','1.8','A'],
				['Gecko','Netscape 7.2','Win 95+ / Mac OS 8.6-9.2','1.7','A'],
				['Gecko','Netscape Browser 8','Win 98SE+','1.7','A'],
				['Gecko','Netscape Navigator 9','Win 98+ / OSX.2+','1.8','A'],
				['Gecko','Mozilla 1.0','Win 95+ / OSX.1+',1,'A'],
				['Gecko','Mozilla 1.1','Win 95+ / OSX.1+',1.1,'A'],
				['Gecko','Mozilla 1.2','Win 95+ / OSX.1+',1.2,'A'],
				['Gecko','Mozilla 1.3','Win 95+ / OSX.1+',1.3,'A'],
				['Gecko','Mozilla 1.4','Win 95+ / OSX.1+',1.4,'A'],
				['Gecko','Mozilla 1.5','Win 95+ / OSX.1+',1.5,'A'],
				['Gecko','Mozilla 1.6','Win 95+ / OSX.1+',1.6,'A'],
				['Gecko','Mozilla 1.7','Win 98+ / OSX.1+',1.7,'A'],
				['Gecko','Mozilla 1.8','Win 98+ / OSX.1+',1.8,'A'],
				['Gecko','Seamonkey 1.1','Win 98+ / OSX.2+','1.8','A'],
				['Gecko','Epiphany 2.20','Gnome','1.8','A'],
				['Webkit','Safari 1.2','OSX.3','125.5','A'],
				['Webkit','Safari 1.3','OSX.3','312.8','A'],
				
			];	
			
			$(document).ready(function() {
			
			
			editor = new $.fn.dataTable.Editor( {
        
        "fields": [ {
                "label": "Nazwa (PL)",
              
            }, {
                "label": "Nazwa (ENG)",
                
            }, {
                "label": "Ilość osób",
                
            }, {
                "label": "Ilość osób",
                
            }, {
                "label": "",
                
            }
        ]
    } );
			
			// New record
    $('a.editor_create').on('click', function (e) {
        e.preventDefault();
 
        editor.create(
            'Create new record',
            { "label": "Add", "fn": function () { editor.submit() } }
        );
    } );
 
    // Edit record
    $('#example').on('click', 'a.editor_edit', function (e) {
        e.preventDefault();
 
        editor.edit(
            $(this).parents('tr')[0],
            'Edit record',
            { "label": "Update", "fn": function () { editor.submit() } }
        );
    } );
 
    // Delete a record (without asking a user for confirmation)
    $('#example').on('click', 'a.editor_remove', function (e) {
        e.preventDefault();
 
        editor.remove( $(this).parents('tr')[0], '123', false, false );
        editor.submit();
    } );
		 
			
						
				$('#dynamic').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
				$('#example').dataTable( {
					"aaData": aDataSet,
					"aoColumns": [
						{ "sTitle": "Nazwa (PL)" },
						{ "sTitle": "Nazwa (ENG)" },
						{ "sTitle": "Ilość osób" },
						{ "sTitle": "Ilość osób", "sClass": "center" },
						{ "sTitle": "", "sClass": "center" },
						
								
						{
                
                "sClass": "center",
                "sDefaultContent": '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'
            }
						
					]
				} );	
			} );
		
					
		</script>

Viewing all articles
Browse latest Browse all 82123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>