question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there any function similar to insertTemplate and editTemplate for deleting rows?

See original GitHub issue

In my archive variable_group.js I inserted the js-GRID database.

And in my archive main.js I declared it.

I want to perform some deleting actions inside the main.js but I don’t know how to access the deleteItem function. Is there any way to do it? (So far for inserting and editing of column Name I successfully used insertTemplate and editTemplate.).

Here I have the codes of variable_group.js and main.js :

  1. variable_group.js :
(function() {
	
	var total_variable_group_ids = 1;

    var variable_group = {

        loadData: function(filter) {
            return $.grep(variable_group.clients, function(client) {
                return (!filter.ID || client.ID.indexOf(filter.ID) > -1)
					&& (!filter.Name || client.Name.indexOf(filter.Name) > -1)
                    && (!filter.Display_name || client.Display_name.indexOf(filter.Display_name) > -1)
					&& (!filter.Order || client.Order === filter.Order)
					&& (!filter.Image || client.Image.indexOf(filter.Image) > -1)
					&& (filter.Buttons === undefined || client.Buttons === filter.Buttons);
            });
        },
		
		

        insertItem: function(insertingClient) {
			insertingClient.ID = total_variable_group_ids;
            this.clients.push(insertingClient);
			$("#GroupJson").html(JSON.stringify(this.clients));
			total_variable_group_ids++;
        },

        updateItem: function(updatingClient) {		
			$("#GroupJson").html(JSON.stringify(this.clients));
		},
		
			
        deleteItem: function(deletingClient) {
            var clientIndex = $.inArray(deletingClient, this.clients);
            this.clients.splice(clientIndex, 1);
			$("#GroupJson").html(JSON.stringify(this.clients));
        }

    };
	

    variable_group.clients = [];

	window.variable_group = variable_group;
	
   
	
}());

  1. main.js :
groupButton:function(){
			
		$( "#VariableGroupGrid" ).dialog({minWidth: 900, minHeight: 500});
		$("#VariableGroupGrid").jsGrid({
                height: "100%",
                width: "70%",
                filtering: true,
                editing: true,
                inserting: true,
                sorting: true,
                paging: true,
                autoload: true,
                pageSize: 15,
                pageButtonCount: 5,
				onItemUpdating: function(args) {
										  previousValue = args.previousValue;
										  },
                deleteConfirm: "Do you really want to delete the row?",
                controller: variable_group,
                fields: [
					{ name: "ID", align: "center", width: 10 },
                    { name: "Name", 
					
					
					
					/*INSERT SELECT BOX*/
					insertTemplate: function() {
						
					//Access the current text field
					var variableGroupInsertResult = jsGrid.fields.text.prototype.insertTemplate.call(this);
					
					//When the value of this textfield is changed pass it to the Process Variables grid
					variableGroupInsertResult.on("change", function() {
					
					//Get the value of this text field
					var selectedInsertValue = variableGroupInsertResult.val();
					
					//Declare the Select option
					var selectOption = {Name: selectedInsertValue , Id: numberOfID};
					
					//Push the Select option to the array of Select box
					process_variables.group.push(selectOption);
					
					//Increase the number of select option reference Id
					numberOfID++;
					
					});
					
					return variableGroupInsertResult;
					}, 
							
					/*EDIT CONTROL*/
					editTemplate: function(previousValue) {
						
					/*Find all the Process Variables with Group value  the previous value and
					**Replace the Process Variables Group previous  value with the new one  
					*/
						
					//Access the current text field
					var variableGroupEditResult = jsGrid.fields.text.prototype.editTemplate.call(this);
					
					//When the value of this textfield is changed pass it to the Process Variables grid
					variableGroupEditResult.on("change", function() {
					
					//Get the edited value of this text field
					var selectedEditValue = variableGroupEditResult.val();
										
					for(var i = 0; i <process_variables.clients.length; i++) {
						//alert(JSON.stringify(process_variables.clients[i].Group));
						if (process_variables.clients[i].Group == previousValue){
						process_variables.clients[i].Group = selectedEditValue;	
						}
						
					}
					
					//Change the configuration of Process Variables Select box options
					for(var j = 0; j<process_variables.group.length; j++){
						if(process_variables.group[j].Name ==  previousValue) process_variables.group[j].Name =  selectedEditValue;
					}
					
					//Update the Process variables index div with new info 
					$("#DataJson").html(JSON.stringify(process_variables.clients));
					
					});
					
					return variableGroupEditResult;
					}, 
					
					validate: { message: "Field Name is required", validator: function(message) { return message; } }, align: "center", type: "text", width: 30 },
                    { name: "Display Name", validate: { message: "Field Display Name is required", validator: function(message) { return message; } }, align: "center", type: "text", width: 50 },
                    { name: "Order", align: "center", type: "number", width: 15 },
					{ name: "Image", validate: { message: "Field Image is required", validator: function(message) { return message; } }, align: "center", type: "text", width: 40 },
					{ name: "Buttons", type: "checkbox", title: "Buttons", sorting: false, width: 10 },
					{ type: "control", width: 25 }
                ]
        });
		
		//Variable Group grid should open by default in “Add new” mode (like I have pressed the green + button)
		$("#VariableGroupGrid").find(".jsgrid-mode-button").click();
		 
	},

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Theriodiscommented, Feb 24, 2017

Consider the issue closed.It works perfect. I want to thank you both @maurorulli and @tabalinas very much.

1reaction
maurorullicommented, Feb 24, 2017

try with:

args.item

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - jsGrid
insertTemplate is a function to create insert row cell content. It should return markup as string, DomNode or jQueryElement. editTemplate is a function...
Read more >
Deleting rows from listview bases on a value for a column
1 Answer 1 · Iterate over the data table to find the item to delete · Delete the item (you could consult, for...
Read more >
Insert a new record using ListView with a GridView-like interface
Add a ListView. In the code below, we have used four templates: ItemTemplate , InsertItemTemplate , EditItemTemplate , and EmptyDataTemplate ...
Read more >
Delete Rows Based on a Cell Value (or Condition) in Excel ...
Want to delete rows based on a cell value or a condition? In this tutorial, I cover multiple ways to do this -...
Read more >
Working with Record Templates - Ex Libris Knowledge Center
Users with a Cataloger role can edit the templates they created. ... For holdings records, the Default holdings template can be used outside ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found