I'm using ant design table component. I have "actions" column that I don't want the onRowClick event will trigger in this column.
How can it be done?
http://codepen.io/liron_e/pen/zZjVKZ?editors=001
const { Table, Modal } = antd;
const confirm = (id) => {
Modal.confirm({
title: 'Confirm',
content: 'Bla bla ...',
okText: 'OK',
cancelText: 'Cancel',
});
};
const info = (id) => {
Modal.info({
title: 'Info',
content: 'Bla bla ...',
okText: 'OK',
cancelText: 'Cancel',
});
};
const columns = [
{
key: 'status',
title: 'text',
dataIndex: 'text'
}, {
key: 'actions',
title: 'actions',
dataIndex: 'id',
render: (id) => {
return (
<span>
<a href="#" onClick={() => confirm(id)}>
Clone
</a>
<span className="ant-divider" />
<a href="#" onClick={() => confirm(id)}>
Replace
</a>
</span>
);
}
}
];
const dataSource = [
{
id: '1',
text: 'Hello'
},{
id: '123',
text: 'adsaddas'
},{
id: '123344',
text: 'cvbbcvb'
},{
id: '5665',
text: 'aasddasd'
},
];
ReactDOM.render(
<div>
<Table
columns={columns}
onRowClick={() => this.info()}
dataSource={dataSource}
/>
</div>
, mountNode);
As you can try when pressing on row the info modal would open.
When pressing some action the info and the confirm modals would open, and I would like that only confirm modal would open.
Thanks (:
In your render function:
render: (id) => {
return (
<span>
<a href="#" onClick={(e) => {
e.stopPropagation();
confirm(id);
}}>
Clone
</a>
<span className="ant-divider" />
<a href="#" onClick={() => confirm(id)}>
Replace
</a>
</span>
);
}
Just stop propagation in your action handler:
<span>
<a href="#" onClick={() => confirm(id)}>
Clone
</a>
<span className="ant-divider" />
<a href="#" onClick={() => confirm(id)}>
Replace
</a>
</span>
<Menu.Item onClick={(e)=>{
e.domEvent.stopPropagation();
handleUpdate(id)}}>
Edit
</Menu.Item>
Using react Link we can have a default anchor link functionality by stoping event propagation and trigger event on particular column.
"react-router": "^5.2.0",
import { Link } from "react-router-dom";
render: (value, record) => {
// Conditional checks if needs to handle on particular set of column
return (
<Link to={'TARGET_LINK_HERE'}
target="_blank" rel="noopener noreferrer"
onClick={(event) => {
event.stopPropagation(); // prevent event to propogate to parent to have row click which is default functionality
}}>{value}</Link>
)
}
Related
{
field: "Id",
title: "#T("Admin.Common.Download")",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" },
template: '<a class="btn btn-default" href="DownloadPdf/?downloadGuid=#=downloadGuid#" title="Download" ><i class="fa fa-download" aria-hidden="true"></i></a>'
}
in template section I need if downloadGuid is not empty then Download icon will show otherwise not.
If we want to add If else condition in kendo grid we want to add # before and after condition.
template: '#if (downloadGuid!=null) { #<a class="btn btn-default" href="DownloadPdf/?downloadGuid=#=downloadGuid#" title="Download" ><i class="fa fa-download" aria-hidden="true"></i></a> # }#'
I want to load every year's data in jqgrid when I click on a button and after loading a modal form and selecting the year from drop down list. a diagram of the steps
but i don't know how to do this.
And this is my source code :
<!-- Page content -->
<div class="w3-content" style="max-width: 100%">
<div class="container" style="width:40%;margin-top:2%">
Filter
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
×
</div>
<div class="modal-body">
<form id="myForm" dir="rtl">
<div class="form-group">
<label>Year</label>
#Html.DropDownListFor(model => model.YEAR_ABBR, ViewBag.YearList as MultiSelectList, "--select--", new { #class = "form-control", #id = "ddlYear", multiple = "multiple" })
</div>
</form>
</div>
<div class="modal-footer">
Cancel
<input type="reset" value="GetRep" class="btn btn-success" id="btnSubmit" />
</div> </div>
</div> </div> </div>
<div dir="rtl" align="center" style="overflow:auto" class="tablecontainer">
<div id="rsperror"></div>
<table id="list" cellpadding="0" cellspacing="0"></table>
<div id="pager" style="text-align:center;"></div>
</div>
Now my script is something like this:
<script type="text/javascript">
$(document).ready(function () {
bindData();
$("#btnSubmit").click(function () {
$('#list').trigger('reloadGrid'); })
});
var bindData = function () {
$('#list').jqGrid({
url: '#Url.Action("Get_RepContracts","Home")',
postData: { YEAR_ABBR: function () { return $('#YEAR_ABBR').val(); } },
datatype: 'json',
jsonReader: {
root: "Rows",
page: "Page",
},
mtype: 'GET',
//columns names
colNames: ['Vahed_Descript' ],
colModel: [
{ name: 'Vahed_Descript', index: 'Vahed_Descript', align: 'right', width: 200, sorttype: "number", }
],
pager: $('#pager'),
rowNum: 800,
rowList: [ 800 ,1000],
sortname: 'Vahed_Descript',
hidegrid: false,
direction: "rtl",
gridview: true,
rownumbers: true,
footerrow: true,
userDataOnFooter: true,
loadComplete: function () {
calculateTotal();
$("tr.jqgrow:odd").css("background", "#E0E0E0");
},
loadError: function (xhr, st, err) {
jQuery("#rsperror").html("Type: " + st + "; Response: " + xhr.status + " " + xhr.statusText);
} , loadonce: true
}) ;
And here the button code ( My modal form works well. when I click the filter button, the filter options in my modal form appear, and then I select the year from year dropdownlist in modal and then i click the report button, after that the below code fires and I can see the selected year's data in action "Get_RepContracts" but it does not bind to my jqgrid):
Thanks in Advance...
UPDATE : Now My code is like below :
$(document).ready(function () {
bindData();
$("#btnSubmit").click(function () {
var myPostData = $('#list').jqGrid("getGridParam", "postData");
$('#list').trigger('reloadGrid');
$("#myModal").modal("hide");
}) });
var bindData = function () {
$('#list').jqGrid({
url: '#Url.Action("Get_RepContracts","Home")',
postData: {
YEAR_ABBR : function () { return $("#YEAR_ABBR").val();},
} ,
datatype: 'json',
jsonReader: { ........
It seems to me that you have small problem with the usage of correct id of select element. Your HTML code contains #id = "ddlYear" parameter of #Html.DropDownListFor:
#Html.DropDownListFor(
model => model.YEAR_ABBR,
ViewBag.YearList as MultiSelectList,
"--select--",
new {
#class = "form-control",
#id = "ddlYear",
multiple = "multiple"
}
)
but you still use
postData: {
YEAR_ABBR: function () { return $("#YEAR_ABBR").val(); }
}
To solve the problem you should just modify the code to
postData: {
YEAR_ABBR: function () { return $("#ddlYear").val(); }
}
I'm trying to make a simple multi-step form for my Rails 5 app using Vue.js. It's my first time using Vue so I am a bit stuck on how to make things work properly.
Right now I am trying to do the following:
Click a Next button and set the li elements from step 1 to step N to have a class active.
Click a Previous button and remove class active from step N.
Quite simple. Here's what I've got so far but I don't know where to go from here:
import Vue from 'vue/dist/vue.esm'
document.addEventListener('DOMContentLoaded', () => {
Vue.component('step-item', {
props: ['step'],
template: '<li :class="{active: isActive}">{{ step.text }}</li>',
data: function() {
return {
isActive: true // Right now I set them all to true
}
}
})
Vue.component('step-button', {
props: ['name'],
template: "<input :name='name' :value='name' #click='counter += 1' type='button' class='btn btn-secondary' />"
})
const progress = new Vue({
el: '#vue-listing',
data: {
counter: 0,
stepList: [
{id: 0, text: 'Basics'},
{id: 1, text: 'Location'},
{id: 2, text: 'Images'},
{id: 3, text: 'Other'}
]
},
methods: {
addProgress: function() {return true}, // todo
delProgress: function() {return true} // todo
}
})
})
then I have my form
<div id="vue-listing">
<!-- Display the progress through the form -->
<ul class="text-center" id="listing-progressbar">
<step-item v-for="item in stepList" :step="item" :key="item.id"></step-item>
</ul>
<fieldset>
Step 1
<step-button name="Next"></step-button>
</fieldset>
<fieldset>
Step 2
<step-button name="Previous"></step-button>
<step-button name="Next"></step-button>
</fieldset>
</div>
Right now I'm stuck on how to get the next and previous buttons to add or remove active from the current step.
Eventually I will also need to hide and display the <fieldset> elements depending on the step.
Any help is much appreciated!
Thanks
A simple implementation of this idea might look something like this.
console.clear()
document.addEventListener('DOMContentLoaded', () => {
Vue.component('step-item', {
props: ['step', 'active'],
template: '<li :class="{active}">{{ step.text }}</li>',
})
const progress = new Vue({
el: '#vue-listing',
data: {
activeStep: 0,
stepList: [
{id: 0, text: 'Basics'},
{id: 1, text: 'Location'},
{id: 2, text: 'Images'},
{id: 3, text: 'Other'}
]
},
methods: {
addProgress: function() {return true}, // todo
delProgress: function() {return true}, // todo
},
})
})
.active {
color: Blue
}
<script src="https://unpkg.com/vue#2.4.2"></script>
<div id="app">
<div id="vue-listing">
<!-- Display the progress through the form -->
<ul class="text-center" id="listing-progressbar">
<step-item v-for="item, ndx in stepList"
:step="item"
:key="item.id"
:active="ndx === activeStep">
</step-item>
</ul>
<fieldset v-if="activeStep === 0">
Step 1
</fieldset>
<fieldset v-if="activeStep === 1">
Step 2
</fieldset>
<fieldset v-if="activeStep === 2">
Step 3
</fieldset>
<fieldset v-if="activeStep === 3">
Step 4
</fieldset>
<hr>
<button #click="activeStep--" :disabled="activeStep === 0">Prev</button>
<button #click="activeStep++" :disabled="activeStep === stepList.length - 1">Next</button>
</div>
</div>
I eliminated the step-button and moved the navigation out of the individual steps. Instead, there are now just buttons that will increment/decrement the current active step. Additionally the fieldsets will now show/hide as needed. Whether or not any individual step is active is passed through the active property.
I have a modal in my Rails app that appears when you click on a button called "New Post." You can then fill out a form and it will create a post. This is all handled with React (if that matters). RSpec is unable to find any element within the modal. Here is my test:
require 'rails_helper'
RSpec.feature "Creating a post" do
before do
#user = User.create(email:"email#gmail.com", password: "password")
end
scenario "A valid user creates a post" do
visit '/'
click_link 'Login'
fill_in "Email", with: "email#gmail.com"
fill_in "Password", with: "password"
click_button "Log in"
click_link "New Post"
expect(page).to have_content("Create a Post")
end
end
Here is the error this test throws:
expected to find text "Create a Post" in "Toggle navigation ReactBlog Home Logout New Post
I tried adding sleeps to see if the animation in the toggle was doing it, but nothing happened. Here is the full React class that contains the modal. Any thoughts would be helpful.
var Posts = React.createClass({
getInitialState: function(){
return {
posts: this.props.posts,
post: {
title: '',
author: '',
content: '',
video: ''
}
}
},
handlePostCreate: function(){
var that = this;
$.ajax({
method: 'POST',
data: { post: that.state.post },
url: '/posts.json',
success: function(res){
var newPostList = that.state.posts;
newPostList.push(res);
that.setState({
posts: newPostList,
post: {
title: '',
author: '',
content: '',
video: ''
}
});
}
});
},
handlePostDelete(post){
var postList = this.state.posts.filter(function(item) {
return post.id !== item.id;
});
this.setState({posts: postList});
},
handleTitleChange(e) {
var newPost = this.state.post
newPost.title = e.target.value
this.setState({post: newPost});
},
handleAuthorChange(e) {
var newPost = this.state.post
newPost.author = e.target.value
this.setState({post: newPost});
},
handleContentChange(e) {
var newPost = this.state.post
newPost.content = e.target.value
this.setState({post: newPost});
},
handleVideoChange(e) {
var newPost = this.state.post
newPost.video = e.target.value
this.setState({ post: newPost });
},
render: function(){
var that = this;
var postBoard = this.state.posts.map(function(post){
return (
<Post post={post} key={post.id} onDeletePost={that.handlePostDelete} />
);
});
return (
<div>
<div className="modal fade" id="myModal" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Create a Post</h4>
</div>
<div className="modal-body">
<div className='form-group'>
<input value={this.state.post.title} onChange={this.handleTitleChange} type='text' id="Title" className='form-control' placeholder="Title" />
</div>
<div className='form-group'>
<input value={this.state.post.author} onChange={this.handleAuthorChange} type='text' className='form-control' placeholder="Author" />
</div>
<div className='form-group'>
<input value={this.state.post.video} onChange={this.handleVideoChange} type="text" className='form-control' placeholder="Video URL" />
</div>
<div className='form-group'>
<textarea value={this.state.post.content} onChange={this.handleContentChange} type="text" className="form-control" placeholder="Content" ></textarea>
</div>
</div>
<div className="modal-footer">
<button type="button" onClick={this.handlePostCreate} className="btn btn-primary" data-dismiss="modal">Post</button>
</div>
</div>
</div>
</div>
{ postBoard }
</div>
);
}
});
You have to enable javascript for the test.
scenario "A valid user creates a post", js: true do
...
end
Also, try adding save_and_open_page to see if you're getting what's expected
scenario "A valid user creates a post", js: true do
...
save_and_open_page
end
I have a Datatable that display data from a table (role) and i use an ajax call to delete a row :
function OnDeleteClick(el)
{
//var url = ($(this).attr('href'));
//alert(url);
//var employeeId = event.getAttribute(id); //e.target.id
//var url = ($(this).attr('id'));
var id = $(el).attr('id');
var roleid = getURLParameter(id, 'id');
var username = getURLParameter(id, 'name');
var flag = confirm('You are about to delete Role ' + username + ' permanently.Are you sure you want to delete this record?');
if (flag) {
$.ajax({
url: '/Role/DeleteAJAX',
type: 'POST',
data: { roleId: roleid },
dataType: 'json',
//success: function (result) { alert(result); $("#" + Name).parent().parent().remove(); },
success: function (result) {
alert(result);
},
error: function () { alert('Error!'); }
});
}
return false;
}
My question is how to refresh the jquery datatable once the delete has succeed, so the deleted row will be also deleted from the datatable?
Below is the code that i use to build my JQuery datatable :
<div class="row" >
<fieldset class="col-md-10 col-md-offset-1" >
<legend>Liste des rôles </legend>
<div class="table-responsive" style="overflow-x: hidden;">
<table width="98%" class="table table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>Designation Role</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#item.Name
</td>
<td width="110">
<a class="btn btn-custom btn-xs" href="" onclick="return getbyID('#item.Id',false)" title="consulter">
<i class="fa fa-folder-open-o"></i>
</a>
<a class="btn btn-custom btn-xs" href="" onclick="return getbyID('#item.Id',true)" title="Editer">
<i class="fa fa-edit"></i>
</a>
<a class="btn btn-custom btn-xs" onclick="OnDeleteClick(this);" id="#?id=#item.Id&name=#item.Name" title=" supprimer">
<i class="fa fa-trash-o"></i>
</a>
</td>
</tr>
}
</tbody>
</table>
</div>
<div class="b-right">
<button type="button" class="btn btn-primary" onclick="location.href='#Url.Action("Create", "Role")'">
<i class="fa fa-plus"></i> Ajouter un role
</button>
</div>
</fieldset>
</div>
Thanks for your help.
If you are using DataTables.net and you built your table like this with an AJAX data source:
var myTable = $("#myTable").DataTable({ ajax: "path/to/my/data" });
You can refresh the data in the table like this:
$.ajax({
<your deleting code>
success: function() {
myTable.ajax.reload();
})
});
If you've built your table with Razor using the view model from MVC, you will need to either 1) reload the page in the success callback:
$.ajax({
<your deleting code>
success: function() {
window.location.reload();
})
});
or 2) remove the row from the DOM, knowing it's already deleted from the database, to keep the DB and the UI in sync:
$.ajax({
<your deleting code>
success: function() {
myTable.row($(el).parents("tr")).remove().draw();
})
});